HtmlUnit Driver
This is currently the fastest and most lightweight implementation of WebDriver. As the name suggests, this is based on HtmlUnit. HtmlUnit is a java based implementation of a WebBrowser without a GUI. For any language binding (other than java) the Selenium Server is required to use this driver.
这个driver是当前最快的driver实现
Usage
WebDriver driver = new HtmlUnitDriver(); //java的使用方式
driver = webdriver.Remote("http://localhost:4444/wd/hub", webdriver.DesiredCapabilities.HTMLUNIT) //python的使用方式
Pros
- Fastest implementation of WebDriver //最快的
- A pure Java solution and so it is platform independent. //纯java实现,所以是跨平台的
- Supports JavaS
cript //支持js Cons
- Emulates other browsers’ JavaS
cript behaviour (see below) JavaS
cript in the HtmlUnit Driver //如何开启javas cript的支持 None of the popular browsers uses the JavaS
cript engine used by HtmlUnit (Rhino). If you test JavaS cript using HtmlUnit the results may differ significantly from those browsers. When we say “JavaS
cript” we actually mean “JavaS cript and the DOM”. Although the DOM is defined by the W3C each browser has its own quirks and differences in their implementation of the DOM and in how JavaS cript interacts with it. HtmlUnit has an impressively complete implementation of the DOM and has good support for using JavaS cript, but it is no different from any other browser: it has its own quirks and differences from both the W3C standard and the DOM implementations of the major browsers, despite its ability to mimic other browsers. With WebDriver, we had to make a choice; do we enable HtmlUnit’s JavaS
cript capabilities and run the risk of teams running into problems that on ly manifest themselves there, or do we leave JavaS cript disabled, knowing that there are more and more sites that rely on JavaS cript? We took the conservative approach, and by default have disabled support when we use HtmlUnit. With each release of both WebDriver and HtmlUnit, we reassess this decision: we hope to enable JavaS cript by default on the HtmlUnit at some point. Enabling JavaS
cript If you can’t wait, enabling JavaS
cript support is very easy: HtmlUnitDriver driver = new HtmlUnitDriver(true); //java的调用方式driver = webdriver.Remote("http://localhost:4444/wd/hub", webdriver.DesiredCapabilities.HTMLUNITWITHJS) //python的调用方式
This will cause the HtmlUnit Driver to emulate Firefox 3.6’s JavaS
cript handling by default. //上述代码会使得 HtmlUnit Driver 模拟 Firefox3.6 对 JavaS
cript 的处理。
java:
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), DesiredCapabilities.htmlUnitWithJs());
python:
driver = webdriver.Remote("http://localhost:4444/wd/hub", webdriver.DesiredCapabilities.HTMLUNITWITHJS)