最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - How to enable javascript in HtmlUnit - Stack Overflow

programmeradmin2浏览0评论

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 plete this operation is not yet available.] sourceName=[.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?

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 plete this operation is not yet available.] sourceName=[http://easypay.swiss.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?

Share Improve this question edited Nov 18, 2015 at 14:08 Ahmed Ashour 5,61110 gold badges39 silver badges62 bronze badges asked Nov 18, 2015 at 13:04 Suresh SSuresh S 812 silver badges9 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

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.

发布评论

评论列表(0)

  1. 暂无评论