如何告诉Selenium使用HTMLUnit?
我在后台运行selenium-server-standalone-2.0b1.jar作为selenium服务器,并使用“pip install-U selenium”安装最新的Python绑定。
Firefox一切正常。但我想使用HTMLUnit,因为它重量较轻,不需要X。这是我的尝试:
>>> import selenium
>>> s = selenium.selenium("localhost", 4444, "*htmlunit", "http://localhost/")
>>> s.start()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/selenium/selenium/selenium.py", line 189, in start
result = self.get_string("getNewBrowserSession", start_args)
File "/usr/local/lib/python2.6/dist-packages/selenium/selenium/selenium.py", line 223, in get_string
result = self.do_command(verb, args)
File "/usr/local/lib/python2.6/dist-packages/selenium/selenium/selenium.py", line 217, in do_command
raise Exception, data
Exception: Failed to start new browser session: Browser not supported: *htmlunit
Supported browsers include:
*firefox
*mock
*firefoxproxy
*pifirefox
*chrome
*iexploreproxy
*iexplore
*firefox3
*safariproxy
*googlechrome
*konqueror
*firefox2
*safari
*piiexplore
*firefoxchrome
*opera
*iehta
*custom
所以问题是,HTMLUnit驱动程序叫什么?如何启用它?
HTMLUnit的代码似乎在Selenium 2的源代码中,所以我希望它在默认情况下与其他浏览器一样可用。我找不到任何关于如何启用它的说明。
我是这样用的:
使用selenium 2.20.0.jar服务器和匹配的python版本,我可以通过将浏览器指定为*mock来使用HtmlUnitDriver
从python客户端的2.0b3版本开始,您可以通过远程连接创建HTMLUnit webdriver,如下所示:
您还可以为支持Javascript的浏览器使用
HTMLUNITWITHJS
功能项。注意,您需要运行Selenium Java服务器才能正常工作,因为HTMLUnit是在Java端实现的。
相关问题 更多 >
编程相关推荐