Module 11 : Error running HtmlUnitDriver | Selenium Forum
M
Posted on 01/08/2016
Hi,

I was trying to run this simple code:

HtmlUnitDriver hd = new HtmlUnitDriver();
hd.get("http://www.google.com");
System.out.println(hd.getTitle());

Imported the package: import org.openqa.selenium.htmlunit.HtmlUnitDriver;

Below is the error message that I get when running the code:

Exception in thread "main" org.openqa.selenium.WebDriverException: java.lang.IllegalArgumentException: Cannot locate declared field class org.apache.http.impl.client.HttpClientBuilder.dnsResolver
Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:32:46'
System info: host: 'CACDTL01cr174k', ip: '129.245.70.144', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_79'
Driver info: driver.version: HtmlUnitDriver
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:543)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:517)
at Drivers.main(Drivers.java:53)
Caused by: java.lang.IllegalArgumentException: Cannot locate declared field class org.apache.http.impl.client.HttpClientBuilder.dnsResolver
at org.apache.commons.lang3.Validate.isTrue(Validate.java:155)
at org.apache.commons.lang3.reflect.FieldUtils.readDeclaredField(FieldUtils.java:512)
at com.gargoylesoftware.htmlunit.HttpWebConnection.getField(HttpWebConnection.java:1038)
at com.gargoylesoftware.htmlunit.HttpWebConnection.createConnectionManager(HttpWebConnection.java:961)
at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:166)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1357)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1274)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:382)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:304)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:451)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:528)
... 2 more

I have tried adding the following jars:

htmlunit-driver-standalone-2.21.jar and
httpclient-win-4.5.2.jar

But still getting the same issue. Please help

Regards,
Budhajit Roy

M
Replied on 02/08/2016

look at this q/a http://sqa.stackexchange.com/questions/20137/htmlunit-driver-error


M
Replied on 02/08/2016

I checked the url that you have mentioned. (http://sqa.stackexchange.com/questions/20137/htmlunit-driver-error)

It was mentioned there as:

To see which jar is being used:
System.out.println(HttpClientBuilder.class.getProtectionDomain().getCodeSource().getLocation());

It should be "httpclient-4.5.2.jar"

I checked using the above code and found that the HttpClient version that I was using was httpclient-4.5.1.jar.
I download httpclient-4.5.2.jar and change the config to httpclient-4.5.2.jar.

But now I'm not getting any error, but instead of getting the page title.. I get the output as "Proxy Warning".

What else steps do I need to do?


M
Replied on 02/08/2016

send me the full error.