如何使用selenium webdriver在特定URL上启动浏览器

mtn*_*aul 4 selenium webdriver

所以,如果我做以下事情:

 driver = webdriver.Chrome() # this results in the browser displaying the about page
 driver.get("http://somesite.com/")  # now the browser goes to the URL
Run Code Online (Sandbox Code Playgroud)

然后,如果我通过浏览器中的javascript控制台检查历史记录长度,则得到值2.我需要模拟使用URL打开新选项卡或窗口的情况,因此历史长度为1.

提前致谢.

eld*_*111 6

初始化时,可以设置一些特定的标志传递给WebDriver.您可以在此处查看示例(适用于Chrome),还可以链接到完整的交换机列表.以下是如何在java中设置ChromeDriver的主页:

DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches",
        Arrays.asList("--homepage=http://somesite.com/"));
WebDriver driver = new ChromeDriver(capabilities);
Run Code Online (Sandbox Code Playgroud)