Suresh S
Suresh S

Reputation: 81

How to enable javascript in HtmlUnit

This is my coding for HtmlUnit

final WebClient webClient = new WebClient();
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setRedirectEnabled(true);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.setThrowExceptionOnFailingStatusCode(false);
webClient.setTimeout(20000);
//webClient.setSSLClientCertificate(certificateUrl,
       certificatePassword, certificateType);
HtmlPage page1 = (HtmlPage)webClient.getPage("http://oneurl");

But i got error like

WARN APOPERATOR "htmlunit.IncorrectnessListenerImpl" Obsolete content type encountered: 'text/javascript'.
ERROR APOPERATOR "javascript.StrictErrorReporter" runtimeError: message=[The data necessary to complete this operation is not yet available.] sourceName=[http://easypay.swisscom.ch/charging-engine-checkout/js/libs/jquery-1.9.1.min.js] line=[3] lineSource=[null] lineOffset=[0]
WARN APOPERATOR "html.HTMLDocument" getElementById(sizzle-1447848465222) did a getElementByName for Internet Explorer
WARN APOPERATOR "htmlunit.IncorrectnessListenerImpl" Obsolete content type encountered: 'text/javascript'.

Can anyone please help to enable javascript in HtmlUnit?

Upvotes: 1

Views: 7009

Answers (1)

Ahmed Ashour
Ahmed Ashour

Reputation: 5549

This already enables the JavaScript:

webClient.getOptions().setJavaScriptEnabled(true);

What you see in the logs are warning messages that the content type should not be used, but you can safely ignore them.

Upvotes: 5

Related Questions