我正在尝试通过以下代码使用 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.25 版中使用selenium-server-standalone-2.25.0.jar
Python模块。selenium
Selenium 服务器在 localhost 上运行,并且可以与例如DesiredCapabilities.FIREFOX
.
我必须手动安装 htmlunit 吗?selenium 网站说standalone-jar 包含所有依赖项。