When you click and this link brings up another page, htmlUnit can be very verbose for exceptions during navigation. If you click on your browser and open the console, you will probably see these errors, missing links or images, errors when calling scripts.
Those don't need Javascript problems with HtmlUnit.
As I said here, HtmlUnit does not create an HtmlPage object , you can set or modify htmlUnit to prevent unnecessary logs. You can also configure log4j and disable some exceptions.
So, we use these options to support html-nawgating, not stopping at the first error / problem that we use:
webClient.getOptions().setThrowExceptionOnScriptError(false); webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
You can also implement empty classes to stop htmlUnity go verbose on the css / javaScript error console using:
webClient.setCssErrorHandler(new SilentCssErrorHandler()); webClient.setJavaScriptErrorListener(new JavaScriptErrorListener(){});
A small test example:
@Test public void TestCall() throws FailingHttpStatusCodeException, MalformedURLException, IOException { WebClient webClient = new WebClient(BrowserVersion.CHROME); webClient.getOptions().setUseInsecureSSL(true); //ignore ssl certificate webClient.getOptions().setThrowExceptionOnScriptError(false); webClient.getOptions().setThrowExceptionOnFailingStatusCode(false); String url = "https://www.wearvr.com/#game_id=game_4"; HtmlPage myPage = webClient.getPage(url); webClient.waitForBackgroundJavaScriptStartingBefore(200); webClient.waitForBackgroundJavaScript(20000); //do stuff on page ex: myPage.getElementById("main") //myPage.asXml() <- tags and elements System.out.println(myPage.asText()); }
You can also see here Disabling HtmlUnit alerts
source share