如何在Chrome上打開新選項卡。我需要從中獲取一些數據,返回到我的上一個選項卡並輸入數據。我知道如何迭代選項卡,但我無法打開新的選項卡。如何使用操作類在Chrome中打開新選項卡
硒版本:3.5.2
Chrome版本:我使用的是Action class
,只使用它來模擬最終用戶的鼠標操作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("[email protected]");
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 WebDriver與Java打開新選項卡?](https://stackoverflow.com/questions/17547473/how-to-open-a-new-tab-using-selenium-webdriver -with-java) – Madhan
這是針對不同版本的硒和不同的瀏覽器。 –
爲什麼你必須使用'Action'類? – Amol