我正在使用Selenium Webdriver,2.25我有一个本地集线器设置了这个json设置chrome和firefox:
[
{
"browserName": "firefox",
"maxInstances": 5,
"seleniumProtocol": "WebDriver"
},
{
"browserName": "chrome",
"maxInstances": 5,
"seleniumProtocol": "WebDriver"
}
],
我可以像这样启动一个webdriver firefox会话:
capability = getattr(webdriver.DesiredCapabilities, "FIREFOX")
dd=webdriver.Remote('http://localhost:4444/wd/hub', capability)
哪个工作正常,但如果我尝试启动这样的Chrome会话:
capability = getattr(webdriver.DesiredCapabilities, "CHROME")
dd=webdriver.Remote('http://localhost:4444/wd/hub', capability)
我收到此错误:
回溯(最近一次调用最后一次):文件“”,第1行,文件“/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py”,第62行,在init中self.start_session(desired_capabilities,browser_profile)文件“/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py”,第104行,在start_session中的“desiredCapabilities”:desired_capabilities,File“/ usr / local / lib / python2.7 / dist-packages / selenium / webdriver / remote / webdriver.py“,第155行,执行self.error_handler.check_response(响应)文件”/usr/local/lib/python2.7 /dist-packages/selenium/webdriver/remote/errorhandler.py“,第147行,在check_response中引发exception_class(消息,屏幕,堆栈跟踪)selenium.common.exceptions.WebDriverException:消息:无; Stacktrace:方法innerGet在None中抛出错误
但我可以像这样开始直接连接到Chrome:
dd=webdriver.Chrome()
没有任何问题 .
如何通过我的Selenium Hub访问Chrome?
2 回答
您需要设置chrome驱动程序,有关该信息的信息here
UPDATE
基于sample json setup file和第一个链接中提供的步骤,似乎浏览器名称不应该在Upper中,而实际上是小写 .
所以将
CHROME
改为chrome
例
在你的情况下,我会假设
我确实遇到了同样的问题 .
事情是,与Firefox不同,Chrome需要单独的chromdriver.exe作为浏览器和驱动程序之间的桥梁 .
从文档:
Download chromdriver.exe here
并把它放在你的chrome二进制目录中 .
然后我使用.bat文件来启动我的中心列表:
然后我在我的Linux机器上执行以下Python代码,一旦我将chromedriver.exe放入Chrome目录并使用正确的路径参数启动集线器,它就能完美运行:
希望这可以帮助您和其他人遇到同样的问题 . 找到解决方案当然不是将firefox方法视为理所当然和RTFM:Chrome driver documentation