如何通过 Python 绑定将 HtmlUnit 驱动程序与 Selenium 一起使用? [英] How do I use the HtmlUnit driver with Selenium through the Python bindings?
问题描述
我通过 Python 绑定位于 Google 网站来使用 WebDriver.根据文档 这里,它支持四种浏览器:Chrome、IE、Firefox 和 HtmlUnit.我可以使用 from selenium.firefox.webdriver import WebDriver
导入 Firefox 驱动程序,使用 from selenium.chrome.webdriver import WebDriver
导入 Chrome 驱动程序.
没有可比的 HtmlUnit 模块.如何导入 HtmlUnit 驱动程序?
我在 https://stackoverflow.com/找到了答案a/5518175/125170
<块引用>从 python 客户端的 2.0b3 版本开始,您可以创建一个通过像这样的远程连接的 HTMLUnit webdriver:
from selenium import webdriver驱动程序 = webdriver.Remote(required_capabilities=webdriver.DesiredCapabilities.HTMLUNIT)driver.get('http://www.google.com')
<块引用>
您还可以将 HTMLUNITWITHJS 功能项用于浏览器Javascript 支持.
请注意,您需要运行 Selenium Java 服务器才能使其工作,因为 HTMLUnit 是在 Java 端实现的.
I'm using WebDriver through the Python bindings located on Google's site. According to the documentation here, it supports four browsers: Chrome, IE, Firefox, and HtmlUnit. I can import the Firefox driver using from selenium.firefox.webdriver import WebDriver
, and the Chrome driver using from selenium.chrome.webdriver import WebDriver
.
There isn't a comparable HtmlUnit module. How do I import the HtmlUnit driver?
I found the answer at https://stackoverflow.com/a/5518175/125170
As of the 2.0b3 release of the python client you can create an HTMLUnit webdriver via a remote connection like so:
from selenium import webdriver
driver = webdriver.Remote(
desired_capabilities=webdriver.DesiredCapabilities.HTMLUNIT)
driver.get('http://www.google.com')
You can also use the HTMLUNITWITHJS capability item for a browser with Javascript support.
Note that you need to run the Selenium Java server for this to work, since HTMLUnit is implemented on the Java side.
这篇关于如何通过 Python 绑定将 HtmlUnit 驱动程序与 Selenium 一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!