javaseleniumselenium-webdriverhtmlunit-driver

how to resolve htmlUnit WrapsDriver Error


I'm running test with HtmlUnit with selenium 3.13 jar, browser launches successfully, but after than it stops working with below error.

> Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/WrapsDriver
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at org.openqa.selenium.htmlunit.HtmlUnitDriver.toWebElement(HtmlUnitDriver.java:1211)
    at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElementByName(HtmlUnitDriver.java:1341)
    at org.openqa.selenium.By$ByName.findElement(By.java:284)
    at org.openqa.selenium.htmlunit.HtmlUnitDriver$4.call(HtmlUnitDriver.java:2024)
    at org.openqa.selenium.htmlunit.HtmlUnitDriver$4.call(HtmlUnitDriver.java:2020)
    at org.openqa.selenium.htmlunit.HtmlUnitDriver.implicitlyWaitFor(HtmlUnitDriver.java:1660)
    at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:2020)
    at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:798)
    at com.directlegalmail.startup.Startup.scrapDates(Startup.java:89)
    at com.directlegalmail.startup.Startup.main(Startup.java:63)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.WrapsDriver
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 22 more

does anyone knows how to resolve it, I have selenium 3.13 and htmlUnit Driver 2.33

below is my code

driver = new HtmlUnitDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait
(10000,TimeUnit.MILLISECONDS);
logMsg("Browser launched successfully");
driver.get("WebURL");

Solution

  • you need to use htmlUnit Driver with dependencies, download the latest htmlunit-driver-x.xx.x-jar-with-dependencies.jar from github which include WrapsDriver class.