1

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()); 
    }
}
3
  • TestNG Trace is as given below:java.lang.NoClassDefFoundError: com/gargoylesoftware/htmlunit/WebWindowListener at GoogleSearch.testHTMLUnitDriver(GoogleSearch.java:13) Commented 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. Commented Jun 27, 2016 at 2:09
  • Possible duplicate of java.lang.ClassNotFoundException: WebDriver API Commented Jun 27, 2016 at 2:09

2 Answers 2

4

You don't only need the HtmlUnitDriver in your classpath, you also need HtmlUnit itself in the classpath. These are not the same thing. HtmlUnitDriver is the selenium driver that can talk to the HtmlUnit headless browser. Download from here: http://htmlunit.sourceforge.net/

Sign up to request clarification or add additional context in comments.

1 Comment

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
0

You need to add htmlunit-cssparser as dependency

<dependency>
    <groupId>net.sourceforge.htmlunit</groupId>
    <artifactId>htmlunit-cssparser</artifactId>
    <version>1.2.0</version>
    <scope>test</scope>
</dependency>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.