相关文章推荐
乐观的蜡烛  ·  Vite + Vue3 <script ...·  1 年前    · 
眉毛粗的红茶  ·  QT ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Getting java.lang.NoClassDefFoundError: com/gargoylesoftware/htmlunit/WebWindowListener when using HTMLUnitDriver

Ask Question

I am trying to use HTMLUnitDriver in my selenium test to understand how HTMLUnitDriver works. Kindly help me with resolving the issue.

I have added the below jars to the build path in eclipse selenium-java-2.53.0 jars TestNG jar

Added the below jars as these were mentioned in other posts as a solution to the error I encountered. However, the issue remains.

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

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()); 
                TestNG Trace is as given below:java.lang.NoClassDefFoundError: com/gargoylesoftware/htmlunit/WebWindowListener 	at GoogleSearch.testHTMLUnitDriver(GoogleSearch.java:13)
– Rekha
                Jun 26, 2016 at 23:56
                Please take a minute to properly format your code as code and add the error message to the original question and properly format it.
– JeffC
                Jun 27, 2016 at 2:09
                I added all the libraries under lib folder of htmlunit-2.22 and executed my code. I encountered the error  in  TestNG trace -   org.openqa.selenium.WebDriverException: java.lang.IllegalArgumentException: Cannot locate declared field class org.apache.http.impl.client.HttpClientBuilder.dnsResolver
– Rekha
                Jun 29, 2016 at 17:57
<dependency>
    <groupId>net.sourceforge.htmlunit</groupId>
    <artifactId>htmlunit-cssparser</artifactId>
    <version>1.2.0</version>
    <scope>test</scope>
</dependency>
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.