Skip to content

About

WebDriver compatible driver for HtmlUnit headless browser.

Resources

Code of conduct

Security policy

Stars

264 stars

Watchers

41 watching

Forks

Repository files navigation

HtmlUnitDriver Logo

Version 4.52.0 / November 03, 2026

❤️ Sponsor

Maven Central Version

Homepage

htmlunit.org

News

Developer Blog

HtmlUnit@mastodon | HtmlUnit@bsky | HtmlUnit@Twitter

Table of Contents

Overview

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

HtmlUnit is a "GUI-less browser for Java programs". It models HTML documents, has fairly good JavaScript support (which is constantly improving) and is able to work even with quite complex AJAX libraries, simulating Chrome, Firefox or Edge depending on the configuration used.

Using HtmlUnit through the WebDriver API gives you

  • fast test execution - there is no browser process to start, no window to render
  • no external dependencies - a pure Java solution, no browser and no driver binary needs to be installed
  • easy CI integration - runs everywhere a JVM runs, including containers without a display
  • the standard WebDriver API - switch between HtmlUnitDriver and a real browser driver without changing your tests, including cookies, frames, windows, alerts and the Actions API
  • browser simulation - Chrome, Edge, Firefox and Firefox ESR (BrowserVersion), with JavaScript support switched on or off
  • customization of the underlying HtmlUnit WebClient via HtmlUnitDriverOptions (e.g. script error handling, CSS, timeouts, SSL, proxy) - see options
  • Selenium 4 Grid support via the HtmlUnit Remote project

Selenium and JDK compatibility

The driver uses the same version number as the Selenium release it is built for - e.g. HtmlUnitDriver 4.52.0 is for Selenium 4.52.0.

Important

Selenium itself still runs on JDK 11, but starting with version 4.44.0 HtmlUnitDriver requires JDK 17 or higher, because it is based on HtmlUnit 5.x. If you are bound to JDK 11, use HtmlUnitDriver 4.43.0 or older.

👉 Compatibility tables - which HtmlUnitDriver version matches which Selenium release, which HtmlUnit version is used and which JDK is required.

Get it!

Maven

Add to your pom.xml:

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>htmlunit3-driver</artifactId>
    <version>4.52.0</version>
</dependency>

Gradle

Add to your build.gradle:

implementation group: 'org.seleniumhq.selenium', name: 'htmlunit3-driver', version: '4.52.0'

Getting Started

Simple

You can simply use one of the constructors from the HtmlUnitDriver 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);

Customization

HtmlUnit offers many customization options. Similar to the other WebDriver implementations, the HtmlUnitDriverOptions class 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

NOTE: Complete details for the HtmlUnitDriverOptions class can be found here.

A complete example

import org.htmlunit.BrowserVersion;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;

public class HtmlUnitDriverExample {

    public static void main(String[] args) {
        final WebDriver driver = new HtmlUnitDriver(BrowserVersion.CHROME, true);
        try {
            driver.get("https://www.htmlunit.org/");
            System.out.println("Title: " + driver.getTitle());

            for (final WebElement link : driver.findElements(By.tagName("a"))) {
                System.out.println(link.getText() + " -> " + link.getAttribute("href"));
            }
        }
        finally {
            driver.quit();
        }
    }
}

More about using HtmlUnit itself:

Vulnerabilities

HtmlUnitDriver is a thin layer on top of HtmlUnit; please check the HtmlUnit information:

List of Vulnerabilities

Security Policy

Sponsoring

Constantly updating and maintaining the HtmlUnit and HtmlUnitDriver code base already takes a lot of time.

For doing this I need your sponsoring.

Contributing

Pull Requests and all other Community Contributions are essential for open source software. Every contribution - from bug reports to feature requests, typos to full new features - are greatly appreciated.

Please try to keep your pull requests small (don't bundle unrelated changes) and try to include test cases.

If your problem is caused by the browser simulation itself (JavaScript, CSS, DOM, ...), please open the issue in the HtmlUnit project.

Last CI build

The latest builds are available from our Jenkins CI build server

Build Status

Read on if you want to try the latest bleeding-edge snapshot.

Maven

Add the snapshot repository and dependency to your pom.xml:

    <!-- ... -->
    <repository>
        <name>Central Portal Snapshots</name>
        <id>central-portal-snapshots</id>
        <url>https://central.sonatype.com/repository/maven-snapshots/</url>
        <releases>
            <enabled>false</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>

    <!-- ... -->
    <dependencies>
      <dependency>
          <groupId>org.seleniumhq.selenium</groupId>
          <artifactId>htmlunit3-driver</artifactId>
          <version>4.53.0-SNAPSHOT</version>
      </dependency>
      <!-- ... -->
    </dependencies>

    <!-- ... -->

Gradle

Add the snapshot repository and dependency to your build.gradle:

repositories {
  maven { url "https://central.sonatype.com/repository/maven-snapshots/" }
  // ...
}
// ...
dependencies {
    implementation group: 'org.seleniumhq.selenium', name: 'htmlunit3-driver', version: '4.52.0-SNAPSHOT'
  // ...
}

License

This project is licensed under the Apache 2.0 License

Development Tools

Special thanks to:

JetBrains IntelliJ IDEA
JetBrains for providing IntelliJ IDEA under their open source development license and

Eclipse Foundation
Eclipse Foundation for their Eclipse IDE

SmartGit
to Syntevo for their excellent SmartGit!

About

WebDriver compatible driver for HtmlUnit headless browser.

Resources

Code of conduct

Security policy

Stars

264 stars

Watchers

41 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages