【发布时间】:2017-09-06 14:59:28
【问题描述】:
如何在 chrome 上打开新标签页。我需要从中获取一些数据,回到我之前的选项卡并输入数据。我知道如何遍历选项卡,但我无法打开新选项卡。
Selenium 版本:3.5.2
Chrome 版本:60
package Amazon;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
public class VerifyAmazonSignInPage {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "C://Selenium jars/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.get("http://www.amazon.in");
driver.findElement(By.xpath("//span[text()='Hello. Sign in']")).click();
driver.findElement(By.id("ap_email")).sendKeys("seleniumoar1234@gmail.com");
driver.findElement(By.id("ap_password")).sendKeys("*****");
driver.findElement(By.id("signInSubmit")).click();
Actions act = new Actions(driver);
act.keyDown(Keys.CONTROL).sendKeys("t").keyUp(Keys.CONTROL).build().perform();
driver.get("http://www.gmail.com");
}
}
【问题讨论】:
-
那是针对不同版本的 selenium 和不同的浏览器。
-
为什么一定要使用
Action类? -
@4M01 我知道我可以使用 Robot 类,但我想知道是否可以使用 Actions 类。
标签: java eclipse selenium selenium-webdriver