Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用SeleniumWebDriver在特定URL启动浏览器_Selenium_Webdriver - Fatal编程技术网

如何使用SeleniumWebDriver在特定URL启动浏览器

如何使用SeleniumWebDriver在特定URL启动浏览器,selenium,webdriver,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 然后,如果我通过浏览器中的javascript控制台检查历史长度,我会得到一个值2。 我需要模拟这样一种情况:打开一个新的选项卡或窗口时,URL的历史长度为1

因此,如果我执行以下操作:

 driver = webdriver.Chrome() # this results in the browser displaying the about page
 driver.get("http://somesite.com/")  # now the browser goes to the URL
然后,如果我通过浏览器中的javascript控制台检查历史长度,我会得到一个值2。 我需要模拟这样一种情况:打开一个新的选项卡或窗口时,URL的历史长度为1


提前谢谢。

我想您有3种可能的选择。(1可能不是)

备选案文1: 设计自己的
get
方法来执行javascript。大概,
window.location.replace(“http://somesite.com/“”
,因此它不会被记录到历史记录中

备选案文2: 在验证中,只需确保验证
n-1
,以“假装”它不存在

选项3:(不确定这种可能性)
使用,找到一种可以修改
历史记录
对象的方法,只需将初始的
关于:空白
历史记录条目取出。

您可以设置一些特定的标志,以便在初始化WebDriver时传递给它。您可以看到示例(对于Chrome),还有一个指向完整开关列表的链接。以下是如何在java中设置ChromeDriver的主页:

DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches",
        Arrays.asList("--homepage=http://somesite.com/"));
WebDriver driver = new ChromeDriver(capabilities);
options.AddArgument(“--homepage\'url\”); 如下所示,将主页设置为空:
options.AddArgument(“--homepage\”数据:,\”)

我还没试过这个。。但如果是这样的话,我更喜欢这种方法