Selenium Beginner 13 – How to use HtmlUnit Driver


Pre-requisites – Selenium jars should be added to the project.
This is covered in the earlier session on this series.
Selenium Beginner 5 – How to write first Selenium script (java) – 5 Easy Steps

Today we will learn :

1. What is HtmlUnit Driver

2. How to run test with HtmlUnit Driver

HtmlUnitDriver driver = new HtmlUnitDriver();

3. How to emulate other browsers

HtmlUnitDriver driver = new HtmlUnitDriver ( BrowserVersion.CHROME );

Helpful Tips:

How to confirm and validate that your test ran on some specific browser

WebClient webClient = (WebClient) get(driver, “webClient”);

private static Object get(Object object, String field) throws Exception {
Field f = object.getClass().getDeclaredField(field);
return f.get(object);


Interview Section:

Q. What is HtmlUnit Driver technically in Selenium library.

HtmlUnit Browser
HtmlUnit Driver

HtmlUnitDriver documentation

Webdriver documentation

Selenium YouTube Playlist

Send me your comments and feedback

%d bloggers like this: