I installed HtmlUnit and wrote simple test program, to check that everything is working. So, here's my very simple test program with HtmlUnit:
public class Main {
public static void main(String[] args) throws Exception {
WebClient webClient = new WebClient();
HtmlPage page = webClient.getPage("http://htmlunit.sourceforge.net");
webClient.close();
}
}
And when I try to run it, I get this:
Exception in thread "main" java.lang.NoSuchFieldError: INSTANCE
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:144)
at com.gargoylesoftware.htmlunit.HttpWebConnection.configureHttpsScheme(HttpWebConnection.java:597)
at com.gargoylesoftware.htmlunit.HttpWebConnection.createHttpClient(HttpWebConnection.java:532)
at com.gargoylesoftware.htmlunit.HttpWebConnection.getHttpClientBuilder(HttpWebConnection.java:494)
at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:158)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1321)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1238)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:346)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:415)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:400)
at code.elix_x.programs.nfixer.Main.main(Main.java:10)
This happens independently of page i try to get. I could not find fix to that error anywhere. Could this be caused by other APIs they i have installed (Apart from HtmlUnit, i have google apis, gson api, jsoup api and apis required for those)?
Thanks for help!
You need to specify a browser to your WebClient constructor, otherwise you won't be able to connect to the page:
WebClient webClient = new WebClient(BrowserVersion.CHROME);