httpunit中的例外情况

时间:2014-08-27 07:21:50

标签: eclipse typeerror ecmascript-5 classname http-unit

我有一个HttpUnit代码,我试图访问谷歌的官方网站。这是我的代码:

/ **您需要启动的所有内容都在com.meterware.httpunit包中** / import com.meterware.httpunit。*;

/ **这是使用HttpUnit阅读和理解网页的简单示例。 ** / 公共类示例{

public static void main(String[] params) {
    try {

        WebConversation wc = new WebConversation();

        String url = "https://www.yahoo.com";
        WebRequest request = new GetMethodWebRequest(url);
        WebResponse response = wc.getResponse(request);

        // WebLink httpunitLink = response.getFirstMatchingLink(
        // WebLink.MATCH_CONTAINED_TEXT, "HTML" );
        // response = httpunitLink.click();
        System.out.println("The yahoo main page '" + url + "' contains "
                + response.getLinks().length + " links");
    } catch (Exception e) {
        System.err.println("Exception: " + e);
    }
}

}

我在运行代码时遇到以下异常。我使用eclipse作为IDE。

org.mozilla.javascript.EcmaError:TypeError:无法从undefined(httpunit#3)读取属性“className”     在org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3229)     在org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3219)     在org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3235)     在org.mozilla.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3254)     在org.mozilla.javascript.ScriptRuntime.undefReadError(ScriptRuntime.java:3267)     在org.mozilla.javascript.ScriptRuntime.getObjectProp(ScriptRuntime.java:1324)     在org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:2816)     在脚本(httpunit:3)     在org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2251)     在org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:161)     在org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:340)     在org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2758)     在org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:172)     在org.mozilla.javascript.Context.evaluateString(Context.java:1132)     at com.meterware.httpunit.javascript.ScriptingEngineImpl.runScript(ScriptingEngineImpl.java:92)     at com.meterware.httpunit.scripting.ScriptableDelegate.runScript(ScriptableDelegate.java:88)     在com.meterware.httpunit.parsing.NekoDOMParser.runScript(NekoDOMParser.java:151)     at com.meterware.httpunit.parsing.ScriptFilter.getTranslatedScript(ScriptFilter.java:150)     at com.meterware.httpunit.parsing.ScriptFilter.endElement(ScriptFilter.java:131)     在org.cyberneko.html.filters.DefaultFilter.endElement(DefaultFilter.java:249)     在org.cyberneko.html.filters.NamespaceBinder.endElement(NamespaceBinder.java:367)     在org.cyberneko.html.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1015)     在org.cyberneko.html.HTMLTagBalancer.endElement(HTMLTagBalancer.java:888)     在org.cyberneko.html.HTMLScanner $ SpecialScanner.scan(HTMLScanner.java:2831)     在org.cyberneko.html.HTMLScanner.scanDocument(HTMLScanner.java:809)     在org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:478)     在org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:431)     在org.apache.xerces.parsers.XMLParser.parse(未知来源)     在org.apache.xerces.parsers.DOMParser.parse(未知来源)     at com.meterware.httpunit.parsing.NekoHTMLParser.parse(NekoHTMLParser.java:48)     在com.meterware.httpunit.HTMLPage.parse(HTMLPage.java:271)     at com.meterware.httpunit.WebResponse.getReceivedPage(WebResponse.java:1301)     at com.meterware.httpunit.WebResponse.getFrames(WebResponse.java:1285)     at com.meterware.httpunit.WebResponse.getFrameRequests(WebResponse.java:1024)     在com.meterware.httpunit.FrameHolder.updateFrames(FrameHolder.java:179)     在com.meterware.httpunit.WebWindow.updateFrameContents(WebWindow.java:315)     at com.meterware.httpunit.WebClient.updateFrameContents(WebClient.java:526)     在com.meterware.httpunit.WebWindow.updateWindow(WebWindow.java:201)     at com.meterware.httpunit.WebWindow.getSubframeResponse(WebWindow.java:183)     在com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:158)     at com.meterware.httpunit.WebClient.getResponse(WebClient.java:122)     在Example.main(Example.java:14) 例外:com.meterware.httpunit.ScriptException:Script'//用于3pas中的perf信标         rtTop = Number(new Date());

    document.documentElement.className += ' jsenabled';

    if (!("ontouchstart" in document.documentElement)) {
        document.documentElement.className += " no-touch";
    }








    (function(){var k=13,d=4,j=0,a=document.documentElement,b=[a.className],f,c=navigator.plugins,g=k;if(c&&c.length){f=c["Shockwave Flash"];if(f&&f.description){j=parseInt(f.description.match(/\b(\d+)\.\d+\b/)[1],10)||0}}else{while(g--){try{new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+g);j=g;break}catch(h){}}}b.push("flash-"+j);while(j-->d){b.push("flash-gt"+j)}a.className=b.join(" ")})();
    (function(){var j=this,n=/^(on)?load/,b=/^on/,i="addEventListener",f="attachEvent",e="_oc",h="detachEvent",g="removeEventListener",l=j[i],m=j[g],p=j[f],a=j[h],k={},d=0;function c(r,s,q){if(!r||!s){return;}if(n.test(r)){if(!s[e]){var t=++d;s[e]=t;k[t]=s;}}else{if(p&&b.test(r)){p(r,s);}else{if(l){l(r,s,q);}}}}function o(r,s,q){if(!r||!s){return;}if(n.test(r)){var t=s[e];if(t){delete k[t];}}else{if(a&&b.test(r)){a(r,s);}else{if(m){m(r,s,q);}}}}j.OnloadCache={enable:function(){if(l){j[i]=c;j[g]=o;}if(p){j[f]=c;j[h]=o;}},disable:function(){if(l){j[i]=l;j[g]=m;}if(p){j[f]=p;j[h]=a;}},dispatch:function(){var r={type:"load"},q;for(q in k){if(k.hasOwnProperty(q)){k[q](r);}}},reset:function(){k={};}};})();

OnloadCache.enable();

        var setJSCookie = true;
(function () {
    var cookieName = "FBJSC=";
    var cookieValue = "1409123746";
    var cookieIndex = document.cookie.indexOf(cookieName);
    if(cookieIndex >= 0) {
        var oldValue = document.cookie.substr(cookieIndex + cookieName.length, cookieValue.length);
        if(cookieValue <= oldValue) {
            setJSCookie = false;
        }
    }

    if(setJSCookie) {
        document.cookie = cookieName + cookieValue;
    }
})();' failed: org.mozilla.javascript.EcmaError: TypeError: Cannot read property "className" from undefined (httpunit#3)

非常感谢任何帮助。谢谢。enter code here

1 个答案:

答案 0 :(得分:0)

作为httpunit提交者之一,我建议您阅读常见问题解答: http://httpunit.sourceforge.net/doc/faq.html

httpunit的JavaScript支持有限。你得到的错误表明你遇到了比httpunit可以处理的更复杂的JavaScript代码。作为解决方法,您可能希望完全关闭javascript(如果在您的用例中可以这样做)。

以下内容来自HttpUnit的开发者常见问题解答:

HttpUnit 1.x对Javascript的支持是有限的。有一个新的Javascript引擎正在开发中,但由于资源有限,开发几乎停滞不前。 要解决您可能想要的问题

  • 尝试新的脚本引擎
  • 关闭javascript
  • 如果你得到一个org.mozilla.javascript.EcmAError ... undefined ...找到缺少的javascript函数,实现它并为社区提供补丁,请参阅&#34; 6。我如何建议修改httpunit?&#34;