尝试在 HTMLUnit 中使用 getPage 时发生 ClassCastException

ClassCastException when trying to use getPage in HTMLUnit

这是我使用的简单代码片段:

final WebClient client = new WebClient();
final HtmlPage page = client.getPage("http://www.muthead.com/packs/simulator/12-tokearmy-pack");

这给了我以下信息:

Exception in thread "main" ======= EXCEPTION START ========
Exception class=[java.lang.ClassCastException]
com.gargoylesoftware.htmlunit.ScriptException: com.gargoylesoftware.htmlunit.javascript.host.html.HTMLAnchorElement cannot be cast to com.gargoylesoftware.htmlunit.html.HtmlElement
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:921)
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:628)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:515)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:852)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:824)
    at com.gargoylesoftware.htmlunit.InteractivePage.executeJavaScriptFunctionIfPossible(InteractivePage.java:216)
    at com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.executeEventListeners(EventListenersContainer.java:258)
    at com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:322)
    at com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget.fireEvent(EventTarget.java:206)
    at com.gargoylesoftware.htmlunit.html.DomElement.run(DomElement.java:1190)
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:628)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:515)
    at com.gargoylesoftware.htmlunit.html.DomElement.fireEvent(DomElement.java:1195)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.executeEventHandlersIfNeeded(HtmlPage.java:1198)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:238)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:519)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:386)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:304)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:451)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:436)
    at Runner.main(Runner.java:26)
== CALLING JAVASCRIPT ==
  function (l) {
      k.call(i, l);
  }
======= EXCEPTION END ========

奇怪的是,如果我将 link 换成 http://google.com,一切正常。这是否意味着我尝试 link 访问的网页有问题? (即使它是有效的 link)

这最近已修复 2.27-SNAPSHOT,您的测试用例现在通过 latest build(以 'guest' 身份登录)。

请相应更新。