如何在HtmlUnit中启用javascript

y1aodyip  于 2023-06-04  发布在  Java
关注(0)|答案(1)|浏览(187)

这是我为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");

但我得到了错误像

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'.

有没有人可以帮助在HtmlUnit中启用javascript?

z0qdvdin

z0qdvdin1#

这已经启用了JavaScript:

webClient.getOptions().setJavaScriptEnabled(true);

您在日志中看到的是不应使用该内容类型的警告消息,但您可以放心地忽略它们。

相关问题