阅读背景:

Chrome中的Selenium Java新标签 - 无法打开,在同一标签中保持打开URL

来源:互联网 
package javaapplication1;
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;

public class JavaApplication1 {
    public static void main(String[] args) throws InterruptedException {
        System.setProperty("webdriver.chrome.driver", "C:\Users\Aca\desktop\chromedriver.exe");
        // Initialize driver
        WebDriver driver = new ChromeDriver();
        //Maximize browser window
        driver.manage().window().maximize();
        //Go to URL
        driver.get("https://www.google.com");
        //Set timeout
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        // Open new tab  – May be you are stuck here
        driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL + "t");
        //Go to URL
        driver.get("https://www.gmail.com");
        //Set new tab timeout
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);        
    }
}
package javaapplication1;
import java.util.conc



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: