Getting error “java.lang.NoClassDefFoundError: com/gargoylesoftware/htmlunit/WebWindowListener” when using HTMLUnitDriver in selenium test

I’m using HTMLUnitDriver for the first time and getting the below error when I run my test.

java.lang.NoClassDefFoundError: com/gargoylesoftware/htmlunit/WebWindowListener
at GoogleSearch.testHTMLUnitDriver(GoogleSearch.java:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:774)

My Code:

import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.testng.annotations.Test;

public class GoogleSearch {

@Test
public void testHTMLUnitDriver() {

HtmlUnitDriver unitDriver = new HtmlUnitDriver();

unitDriver.get(“https://www.google.co.uk/”);

System.out.println(“Title of the page is:” +unitDriver.getTitle());

}
}

JARS included in the projects build path:
selenium-server-standalone-2.53.0
selenium-htmlunit-driver-2.52.0
selenium-java-2.53.0
TestNG

Kindly help resolve this issue. The post on ToolsQA – http://toolsqa.com/selenium-webdriver/headless-browser-testing-selenium-webdriver/

does not mention anything additional to be done. I added selenium-server-standalone-2.53.0  , selenium-htmlunit-driver-2.52.0  as it was mentioned as a solution on some other blogs.

Thanks,
Rekha

Add Comment
  • 1 Answer(s)

    HI,

    selenium-server-standalone-2.53.0
    selenium-htmlunit-driver-2.52.0
    selenium-java-2.53.0

    can you please try again  by downgrading your version to 2.52.0
    let me know if it works

    thanks

    Vice Professor Answered on June 27, 2016.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.