Prasad_Joshi
Prasad_Joshi

Reputation: 662

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");

Upvotes: 0

Views: 1666

Answers (3)

Stefan Zhelyazkov
Stefan Zhelyazkov

Reputation: 2981

This combination of dependencies worked for me:

implementation("org.seleniumhq.selenium:selenium-java:3.141.59")
implementation("org.seleniumhq.selenium:selenium-api:3.141.59")
implementation("org.seleniumhq.selenium:htmlunit-driver:2.36.0")

You can see the compatible Selenium dependencies for HtmlUnit Driver version 2.36.0 here: https://github.com/SeleniumHQ/htmlunit-driver/blob/2.36.0/pom.xml

Upvotes: 0

ewwink
ewwink

Reputation: 19164

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.

Upvotes: 1

undetected Selenium
undetected Selenium

Reputation: 193308

Some more information about your Test Environment would have given us some more idea what exactly going wrong.

However I don't see any major issues in your code block. With Selenium v3.14 and HtmlunitDriver v2.33.0 while invoking HtmlUnitDriver you need to pass the argument true to enable JavaScript and you can use the following solution:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;

public class A_HtmlunitDriver_2_33_0 {

    public static void main(String[] args) throws InterruptedException {

    WebDriver driver = new HtmlUnitDriver(true);
    driver.manage().window().maximize();
    driver.get("https://stackoverflow.com/questions/53812207/how-to-resolve-htmlunit-wrapsdriver-error");
    System.out.println("HtmlUnitDriver invoked");
    driver.quit();
    }
}

Upvotes: 0

Related Questions