gpt4 book ai didi

java - 面临 HtmlUnitDriver 的问题

转载 作者:行者123 更新时间:2023-12-02 13:44:09 25 4
gpt4 key购买 nike

我正在使用 HtmlUnitDriver 打开链接。这是我的代码:

HtmlUnitDriver webDriver = new HtmlUnitDriver();
webDriver.get("some url here");

但是我遇到了以下异常。

Caused by: com.gargoylesoftware.htmlunit.ScriptException: Wrapped com.gargoylesoftware.htmlunit.ScriptException: Wrapped com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot find function aa in object [object Object]. (https://apis.google.com/_/apps-static/_/js/gapi/plusone/rt=j/ver=use0LfpKko4.en_US./sv=1/am=!CVDWKorrwvOYBs7wcQ/d=1/rs=AItRSTMxl0wiQySaT0IYW5gyOkdlVL9A6A/cb=gapi.loaded_0#3)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:595)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:537)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:538)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:499)
at com.gargoylesoftware.htmlunit.html.HtmlPage.loadExternalJavaScriptFile(HtmlPage.java:973)
at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:349)
at com.gargoylesoftware.htmlunit.html.HtmlScript$1.execute(HtmlScript.java:230)
at com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:240)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:598)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:556)
at org.cyberneko.html.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1142)
at org.cyberneko.html.HTMLTagBalancer.endElement(HTMLTagBalancer.java:1044)
at org.cyberneko.html.filters.DefaultFilter.endElement(DefaultFilter.java:206)
at org.cyberneko.html.filters.NamespaceBinder.endElement(NamespaceBinder.java:329)
at org.cyberneko.html.HTMLScanner$ContentScanner.scanEndElement(HTMLScanner.java:3018)
at org.cyberneko.html.HTMLScanner$ContentScanner.scan(HTMLScanner.java:2005)
at org.cyberneko.html.HTMLScanner.scanDocument(HTMLScanner.java:908)
at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:499)
at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:452)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.parse(HTMLParser.java:789)
at com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:225)
at com.gargoylesoftware.htmlunit.html.HTMLParser.parseHtml(HTMLParser.java:179)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:221)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:106)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:433)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:311)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:373)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:346)
... 15 more

请指导我,如何解决这个问题。我使用的是selenium-java-2.24.1.jar,webdriver-common.jar。

最佳答案

异常表示驱动程序在加载页面时遇到 Javascript 函数问题,默认情况下 HTMLUNITDriver 禁用 Javascript。

您需要显式启用它,然后尝试导航该 URL试试这个,它应该可以工作。

HtmlUnitDriver driver = new HtmlUnitDriver(true);

True --> 这里提到启用Java脚本。

此外,HtmlUnitDriver 使用的 javascript 引擎与其他浏览器不同。请查看此链接以了解更多详细信息。

http://seleniumhq.org/docs/03_webdriver.html#htmlunit-driver

关于java - 面临 HtmlUnitDriver 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12704282/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com