HtmlUnitDriver is a WebDriver compatible driver for the HtmlUnit headless browser.
Please have a look at the HtmlUnit Remote project if you like to use this driver from Selenium 4 Grid.
An overview of the different versions, the HtmlUnit version used in each case and the compatibility can be found in these tables.
Simply add a dependency on the latest htmlunit3-driver
version available in the Maven Central.
Add to your pom.xml
:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>htmlunit3-driver</artifactId>
<version>4.23.0</version>
</dependency>
Add to your build.gradle
:
implementation group: 'org.seleniumhq.selenium', name: 'htmlunit3-driver', version: '4.23.0'
You can simply use one of the constructors from the HtmlUnit driver class
// simple case - no javascript support
WebDriver webDriver = new HtmlUnitDriver();
// specify the browser - no javascript support
WebDriver webDriver = new HtmlUnitDriver(BrowserVersion.FIREFOX);
// simple case - javascript support enabled
WebDriver webDriver = new HtmlUnitDriver(true);
// specify the browser - javascript support enabled
WebDriver webDriver = new HtmlUnitDriver(BrowserVersion.FIREFOX, true);
HtmlUnit offers many customization options. Similar to the other WebDriver's the class HtmlUnitDriverOptions can be used to customize your HtmlUnit driver.
final HtmlUnitDriverOptions driverOptions = new HtmlUnitDriverOptions(BrowserVersion.FIREFOX);
// configure e.g.
driverOptions.setCapability(HtmlUnitOption.optThrowExceptionOnScriptError, false);
HtmlUnitDriver webDriver = new HtmlUnitDriver(driverOptions);
// use the driver
Please check the
An overview of the different versions, the HtmlUnit version used in each case and the compatibility can be found in these tables.
HtmlUnitDriver is distributed under Apache License 2.0.