Skip to content
WebDriver compatible driver for HtmlUnit headless browser.
JavaScript Java HTML Starlark CSS C#
Branch: master
Clone or download

Latest commit

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src the blur event is triggered by HtmlUnit Apr 28, 2020
.gitattributes Refactor and fix HtmlUnitWebElement.getText() Jan 18, 2017
.gitignore exclude bin directory (eclipse) Nov 8, 2017
.travis.yml compile with openjdk8 Oct 1, 2019
LICENSE Initial commit Feb 17, 2016
README.md point to jenkins build Apr 27, 2020
howto.txt update howto Jan 10, 2018
pom.xml start working on 2.40.0-SNAPSHOT Apr 27, 2020

README.md

Build Status

HtmlUnitDriver

HtmlUnitDriver is a WebDriver compatible driver for the HtmlUnit headless browser.

News

Twitter

Download and Installation

Maven/Gradle/...

Add a dependency on the latest htmlunit-driver version available in the Maven Central, please note that both artifactId and version are changed to match the dependent HtmlUnit version:

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>htmlunit-driver</artifactId>
    <version>2.39.0</version>
</dependency>

Usage

Simple

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_68);
// simple case - javascript support enabled
WebDriver webDriver = new HtmlUnitDriver(true);
// specify the browser - javascript support enabled
WebDriver webDriver = new HtmlUnitDriver(BrowserVersion.FIREFOX_68, true);

More customization

HtmlUnit offers a lot more customization options. To adjust these options you can use this pattern.

WebDriver webDriver = new HtmlUnitDriver(BrowserVersion.FIREFOX_68, true) {
    @Override
    protected WebClient modifyWebClient(WebClient client) {
        final WebClient webClient = super.modifyWebClient(client);
        // you might customize the client here
        webClient.getOptions().setCssEnabled(false);

       return webClient;
    }
};

And for some special cases you and also overwrite the method newWebClient(final BrowserVersion version) to adjust the webClient before the standard WebDriver setup takes place or for constructing your own webClient.

License

HtmlUnitDriver is distributed under Apache License 2.0.

You can’t perform that action at this time.