sea*_*ers 8 python selenium selenium-grid phantomjs selenium-webdriver
我用它的默认启动命令启动了一个selenium grid hub,
java -jar selenium-server-standalone-2.33.0.jar -role hub
Run Code Online (Sandbox Code Playgroud)
我在它的webdriver模式下启动PhantomJS,在同一台机器上,比如
phantomjs --webdriver=8080 --webdriver-selenium-grid-hub=http://127.0.0.1:4444
Run Code Online (Sandbox Code Playgroud)
当PhantomJS启动时,除了"All'OK'"消息之外什么都没有,
[INFO - 2013-09-09T18:10:38.849Z] GhostDriver - Main - running on port 8080
[INFO - 2013-09-09T18:10:38.850Z] GhostDriver - Main - registering to Selenium HUB 'http://127.0.0.1:4444' using '127.0.0.1:8080'
[INFO - 2013-09-09T18:11:47.164Z] HUB Register - register - Registered with grid hub: http://127.0.0.1:4444/ (ok)
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试使用该浏览器,请使用
driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub',
desired_capabilities=DesiredCapabilities.PHANTOMJS)
Run Code Online (Sandbox Code Playgroud)
查看PhantomJS可执行文件的输出,
[INFO - 2013-09-09T18:17:12.531Z] Session [0c5c9500-197c-11e3-8eed-b3b7a73965aa] - _decorateNewWindow - page.settings: {"XSSAuditingEnabled":false,"javascriptCanCloseWindows":true,"javascriptCanOpenWindows":true,"javascriptEnabled":true,"loadImages":true,"localToRemoteUrlAccessEnabled":false,"userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.2 Safari/534.34","webSecurityEnabled":true}
[INFO - 2013-09-09T18:17:12.531Z] Session [0c5c9500-197c-11e3-8eed-b3b7a73965aa] - page.customHeaders: - {}
[INFO - 2013-09-09T18:17:12.531Z] Session [0c5c9500-197c-11e3-8eed-b3b7a73965aa] - CONSTRUCTOR - Desired Capabilities: {"platform":"ANY","javascriptEnabled":true,"browserName":"phantomjs","version":""}
[INFO - 2013-09-09T18:17:12.531Z] Session [0c5c9500-197c-11e3-8eed-b3b7a73965aa] - CONSTRUCTOR - Negotiated Capabilities: {"browserName":"phantomjs","version":"1.9.2","driverName":"ghostdriver","driverVersion":"1.0.4","platform":"mac-10.7 (Lion)-32bit","javascriptEnabled":true,"takesScreenshot":true,"handlesAlerts":false,"databaseEnabled":false,"locationContextEnabled":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"cssSelectorsEnabled":true,"webStorageEnabled":false,"rotatable":false,"acceptSslCerts":false,"nativeEvents":true,"proxy":{"proxyType":"direct"}}
[INFO - 2013-09-09T18:17:12.531Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: 0c5c9500-197c-11e3-8eed-b3b7a73965aa
Run Code Online (Sandbox Code Playgroud)
一切似乎都很好,但代码崩溃:/我得到一个巨大的错误堆栈跟踪,主要是,
selenium.common.exceptions.WebDriverException: Message: u'Error forwarding the new session new session request for webdriver should contain a location header with the session.'
Run Code Online (Sandbox Code Playgroud)
如果你检查网格集线器的输出,
INFO: Trying to create a new session on test slot {seleniumProtocol=WebDriver, browserName=phantomjs, maxInstances=1}
INFO: Available nodes: [host :http://127.0.0.1:8080 time out : 300000]
Run Code Online (Sandbox Code Playgroud)
似乎还有一个问题.看起来,无论出于何种原因,网格集线器都不会从PhantomJS可执行文件中获取任何信息,即使它似乎正在正确处理事情.
为了测试,我还有一个常规的selenium节点在同一台机器上运行命令
java -jar selenium-server-standalone-2.33.0.jar -role node
Run Code Online (Sandbox Code Playgroud)
如果我启动Firefox RemoteWebDriver会话(在Python中),请使用
driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub',
desired_capabilities=DesiredCapabilities.FIREFOX)
Run Code Online (Sandbox Code Playgroud)
一切都很好.
看起来所有东西都设置正确,我把东西保持为"香草"并尽可能接近文档所说的内容,但这里无法克服困难.
在Java中尝试时也会发生完全相同的错误
WebDriver driver = new RemoteWebDriver(DesiredCapabilities.phantomjs());
Run Code Online (Sandbox Code Playgroud)
两个连接的网格控制台的截图,PhantomJS还活着,那里很好,
左边是默认的selenium节点,右边是PhantomJS(而10.0.0.222是我工作的笔记本电脑的IP地址).
我的版本对于PhantomJS是1.9.2,对于selenium来说显然是2.33.0.
Jes*_*ord 11
事实证明这是phantomjs的1.9.2版本中的一个错误功能.他们更新到最新的ghostdriver(v1.4)库,我想这就是它的介绍.Ghostdriver遵循新的Selenium协议,使用帖子创建会话而不使用位置标头.Selenium现在从帖子的主体中的json抓取位置等.事实证明,您所看到的错误以及我所看到的错误是因为您正在使用旧的selenium jar,它使用旧式会话创建协议和新版本的selenium.现在你的问题的答案是回到phantomjs 1.9.1将你的selenium jar更新到2.35.0(见下面的链接).为了重现你的错误,我测试了ruby和python selenium webdrivers以及作为hub运行的2.33.0 selenium jar和作为ghostdriver worker运行的phantomjs 1.9.2.
这是github问题中描述的相同错误:
https://github.com/ariya/phantomjs/issues/11610
我相信它与这个特定的提交有关.您可以看到"位置"标题已被删除.
https://github.com/detro/ghostdriver/commit/60bf3c90aa825cc3db4fa899b6a67bb7f109d55d
以下是上述提交针对的问题的描述:https: //github.com/detro/ghostdriver/issues/247
从那里你可以看到这是一个解决方案,使用selenium-webdrivers最新协议:"新规范:https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session Selenium中的变化:https: //code.google.com/p/selenium/source/detail?r=8c3c65772d57 "
它看起来像更新到最新的selenium-webdriver-standalone jar将允许你获得1.9.2工作.我已经确认我的ruby webdriver现在可以与2.35.0 jar和phantomjs 1.9.2成功连接.
你可以在这里获得最新的jar:
归档时间: |
|
查看次数: |
7049 次 |
最近记录: |