2

次のコードで Python から HTMLUnit WebDriver を使用しようとしています。

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.remote.webdriver import WebDriver

if __name__ == '__main__':
    webdriver = WebDriver('http://127.0.0.1:4444/wd/hub', DesiredCapabilities.HTMLUNIT)
    webdriver.get('http://www.google.com')

...次のエラーが発生します。

Traceback (most recent call last):
  File "bcc_mon_webdriver.py", line 8, in <module>
    webdriver = WebDriver('http://127.0.0.1:4444/wd/hub', DesiredCapabilities.HTMLUNIT)
  File "c:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 63, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "c:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 105, in start_session
    'desiredCapabilities': desired_capabilities,
  File "c:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 156, in execute
    self.error_handler.check_response(response)
  File "c:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 147, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: u'Error forwarding the new session cannot find : {platform=ANY, browserName=htmlunit, version=}' ; Stacktrace: Method process threw an error in RequestHandler.java 

バージョン 2.25selenium-server-standalone-2.25.0.jarの Pythonモジュールでも使用します。seleniumSelenium サーバーは localhost で実行されており、たとえばDesiredCapabilities.FIREFOX.

htmlunit を手動でインストールする必要がありますか? セレンのウェブサイトによると、standalone-jar にはすべての依存関係が含まれています。

4

1 に答える 1

2

{platform=ANY, browserName=htmlunit, version=}問題は、パターンに一致するノードがないことです。これを修正するには、次のように、これらのブラウザー設定で Selenium ノードを開始する必要があります。

java -jar selenium-server-standalone-2.25.0.jar -role node -hub http://localhost:4444/grid/register -browser browserName=htmlunit

Selenium wiki ( http://code.google.com/p/selenium/wiki/Grid2 ) には次のように書かれています。

「デフォルトでは、これにより 11 のブラウザが起動します。そのうち 5 つは Firefox、5 つは Chrome、1 つは Internet Explorer です。」

したがって、さまざまなブラウザーを使用できるようにするにhtmlunitは、-browser パラメーターを使用してノードを開始し、desired_capabilities.pyファイル (selenium/webdriver/common/ の下のセレンの卵にある) をチェックして、各ブラウザーに必要なパラメーターの参照を確認する必要があります。 .

于 2012-08-29T07:29:24.813 に答える