HtmlUnit – Welcome to HtmlUnit (original) (raw)

HtmlUnit is a "GUI-Less browser for Java programs". It models HTML documents and provides an API that allows you to invoke pages, fill out forms, click links, etc... just like you do in your "normal" browser.
It 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.
It is typically used for testing purposes or to retrieve information from websites.

HtmlUnit is not a generic unit testing framework. It is specifically a way to simulate a browser for testing purposes and is intended to be used within another testing framework such as JUnit or TestNG. Refer to the document "Getting Started with HtmlUnit" for an introduction.

HtmlUnit is used as the underlying "browser" by different Open Source tools like

HtmlUnit is used by many projects for automated web testing

HtmlUnit was originally written byMike Bowler ofGargoyle Software and is released under the Apache 2 license. Since then, it has received many contributions from other developers, and would not be where it is today without their assistance.

Where to find...

Latest release May 31, 2026

version 5.1.0

Source code

GitHub

News

Mastodon Bluesky Twitter

Latest build / CI server

Jenkins build server

Documentation

Tutorials

Features

Installation

Place all the required jars in your classpath. All of these can be found in the lib directory of the HtmlUnit installation (htmlunit-4.xx.x-bin.zip contains everything you need including all required dependencies).

For maven, you would add:

org.htmlunit htmlunit 5.1.0

For gradle, you would add:

implementation group: 'org.htmlunit', name: 'htmlunit', version: '5.1.0'

If you like to use the latest available snapshot build you have to add the Central Portal Snapshots repository to your pom repositories section; also (checkBsky for regular information about new snapshot builds).

Central Portal Snapshots central-portal-snapshots https://central.sonatype.com/repository/maven-snapshots/ false true

JavaScript Support

HtmlUnit provides excellent JavaScript support, simulating the behavior of the configured browser (Chrone, Firefox or Edge). It uses the Rhino JavaScript engine for the core language (plus workarounds for some Rhino bugs) and provides the implementation for the objects specific to execution in a browser.

The unit tests of some well-known JavaScript libraries are included in HtmlUnit's own unit tests; based on these unit tests, the following libraries are known to work well with HtmlUnit:

JavaScript code is executed just like in normal browsers when the page loads or when a handler is triggered. Additionally, HtmlUnit provides the ability to inject code into an existing page via HtmlPage.executeJavascript(String yourJsCode).

Refer to the Use JavaScript for more details.

Refer to the changes document for details on what is being added.