我正在将Selenium与Java一起使用,并使用JUnit执行测试。它一直告诉我
找不到 Chrome 二进制文件
二进制位置不是标准的,因为我需要测试多个版本。我精确地确定 Chrome.exe 启动器存在于指定的 JSON 位置......
看起来司机仍在标准位置搜索。
我有 JSON 配置文件:
{
"capabilities":[
{
"browserName":"chrome",
"platform":"WINDOWS",
"chromeOptions":{
"binary":"C:/path/chrome_binary.exe"
},
"maxInstance":1
}
],
"configuration":{
"cleanUpCycle":2000,
"timeout":30000,
"register":true,
"hubPort":4444,
"hubHost":"hub.location.net",
"maxSessions":1
}
}
如您所见,我在 Windows 上,所以我尝试了带有斜杠和反斜杠的路径,但它以任何一种方式都不起作用。
ChromeOptions对象应该没问题,我使用了这个官方文档
命令行为:
java -jar selenium-server-standalone.jar -role webdriver -nodeConfig path/to/conf.json -Dwebdriver.chrome.driver=path/to/chromedriver.exe
在代码中,我正在创建RemoteWebDriver对象,并且仅传递浏览器,版本和平台。它与火狐浏览器配合得很好。例如,在 JSON 节点配置中,我已经设置了firefox_binary,而在代码中,我不会将其传递给 DesiredCapabilities。Selenium仍然可以使用我通过上述命令启动的远程Web驱动程序。
谢谢!
终于明白了。没有在任何文档中看到它,因为他们都在谈论binary
或chromeOptions
.
答案就在这里,https://stackoverflow.com/a/33151376/4675568,非常感谢他,简而言之:没有chromeOptions
,只是像火狐一样chrome_binary
键。
"capabilities": [{
"browserName": "chrome",
"platform": "WINDOWS",
"chrome_binary":"C:/path/to/chrome_binary.exe",
"maxInstance":1
}]
Windows 中的路径使用反斜杠:
"binary":"C:\path\chrome_binary.exe"
也许应该应用此更改
"binary":"C://path//chromedriver.exe"
编辑 1
尝试使用此 JSON 配置文件:
{
"capabilities":[
{
"browserName":"chrome",
"platform":"WINDOWS",
"binary":"C:/path/chrome_binary.exe"
"maxInstance":1
}
],
"configuration":{
"cleanUpCycle":2000,
"timeout":30000,
"register":true,
"hubPort":4444,
"hubHost":"hub.location.net",
"maxSessions":1
}
}
最后,尝试转义"/",如下例所示:
"binary":"C://path//chrome_binary.exe"
或
"binary":"C:/path/chrome_binary.exe"