1

I'm using HtmlUnit to grab a page, but it crashes saying it doesn't know of a function "getPropertyValue"

I've tried using the waitInBackground functions to see if would work, but to no avail. I also tried a different web page with javascript, and it worked. Turning off javascript does work, but it is essential.

Trying a different browser does not work, and sometimes it actually gives me a different function name error.

public class WebRequest {

    public static void main(String[] args) {
        java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(
                java.util.logging.Level.OFF);
        java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.OFF);

        WebClient webClient = new WebClient(BrowserVersion.CHROME);
        webClient.getOptions().setJavaScriptEnabled(true);
        HtmlPage page;
        try {
            page = webClient.getPage("http://stackoverflow.com/questions/22032343/htmlunit-crashes-on-javascript");
            System.out.println(page.getWebResponse().getContentAsString());
            System.out.println(page.getTitleText());
        } catch (FailingHttpStatusCodeException e) {
            e.printStackTrace();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}

Error stack trace

 Exception in thread "main" ======= EXCEPTION START ========
    EcmaError: lineNumber=[4] column=[0] lineSource=[  }] name=[TypeError] sourceName=[http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js] message=[TypeError: Cannot find function getPropertyValue in object [object ComputedCSSStyleDeclaration]. (http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js#4)]
    com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot find function getPropertyValue in object [object ComputedCSSStyleDeclaration]. (http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js#4)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:689)
        at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:620)
        at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:513)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:621)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:596)
        at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:997)
        at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventListeners(EventListenersContainer.java:179)
        at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:239)
        at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:827)
        at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:761)
        at com.gargoylesoftware.htmlunit.html.HtmlElement$1.run(HtmlElement.java:917)
        at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:620)
        at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:513)
        at com.gargoylesoftware.htmlunit.html.HtmlElement.fireEvent(HtmlElement.java:922)
        at com.gargoylesoftware.htmlunit.html.HtmlPage.executeEventHandlersIfNeeded(HtmlPage.java:1294)
        at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:252)
        at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:462)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:329)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:394)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:379)
        at WebRequest.main(WebRequest.java:23)
    Caused by: net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot find function getPropertyValue in object [object ComputedCSSStyleDeclaration]. (http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js#4)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3629)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3613)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3634)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3650)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.notFunctionError(ScriptRuntime.java:3714)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getPropFunctionAndThisHelper(ScriptRuntime.java:2233)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2215)
        at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1333)
        at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:798)
        at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105)
        at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:411)
        at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:309)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3057)
        at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:103)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$4.doRun(JavaScriptEngine.java:614)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:674)
        ... 20 more
    Enclosed exception: 
    net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot find function getPropertyValue in object [object ComputedCSSStyleDeclaration]. (http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js#4)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3629)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3613)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3634)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3650)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.notFunctionError(ScriptRuntime.java:3714)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getPropFunctionAndThisHelper(ScriptRuntime.java:2233)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2215)
        at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1333)
        at script(http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js:4)
        at script(http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js:4)
        at script.bC(http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js:2)
        at script(http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js:4)
        at script(http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js:4)
        at script(http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js:4)
        at script(http://cdn.sstatic.net/Js/stub.en.js?v=283ea58c715b:8)
        at script(http://cdn.sstatic.net/Js/stub.en.js?v=283ea58c715b:11)
        at script(http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js:2)
        at script(http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js:2)
        at script(http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js:2)
        at script(http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js:2)
        at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:798)
        at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105)
        at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:411)
        at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:309)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3057)
        at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:103)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$4.doRun(JavaScriptEngine.java:614)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:674)
        at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:620)
        at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:513)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:621)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:596)
        at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:997)
        at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventListeners(EventListenersContainer.java:179)
        at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:239)
        at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:827)
        at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:761)
        at com.gargoylesoftware.htmlunit.html.HtmlElement$1.run(HtmlElement.java:917)
        at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:620)
        at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:513)
        at com.gargoylesoftware.htmlunit.html.HtmlElement.fireEvent(HtmlElement.java:922)
        at com.gargoylesoftware.htmlunit.html.HtmlPage.executeEventHandlersIfNeeded(HtmlPage.java:1294)
        at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:252)
        at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:462)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:329)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:394)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:379)
        at WebRequest.main(WebRequest.java:23)
    == CALLING JAVASCRIPT ==

      function () {
          c.removeEventListener("DOMContentLoaded", B, !1), e.ready();
      }

    ======= EXCEPTION END ========
Brandon Ling
  • 3,841
  • 6
  • 34
  • 49

0 Answers0