0

I am trying to emulate pressing a JS "Continue" button (using HtmlUnit) which submits a hidden form, and then retrieve the HTML/XML source of the page after submitting the form. On a regular browser, the button appears after a 1 second delay (replacing some text). However, upon loading the page in HtmlUnit I receive a Javascript error.

The link is safe if you would like to click it yourself, however it contains a bunch of ads, or you can view-source: to view the source. The JavaScript script ca be found here: http://ajax.cloudflare.com/cdn-cgi/nexp/dokv=97fb4d042e/cloudflare.min.js#3

    String link = "http://www.firedrive.com/file/A550ECCE9DF21DB6";
    final WebClient webClient = new WebClient(BrowserVersion.CHROME);

    //webClient.getOptions().setJavaScriptEnabled(false);
    final HtmlPage page1 = webClient.getPage(link);

    List<HtmlForm> forms = page1.getForms();

    final HtmlForm form = forms.get(1);
    final HtmlHiddenInput button = form.getInputByName("confirm");
    final HtmlPage page2 = button.click();

    System.out.println(page2.asXml());
    webClient.closeAllWindows();

However the following error appears, regarding the server's JS script:

======= EXCEPTION START ========
Exception class=[net.sourceforge.htmlunit.corejs.javascript.WrappedException]
com.gargoylesoftware.htmlunit.ScriptException: Wrapped com.gargoylesoftware.htmlunit.ScriptException: Wrapped com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot find function stopPropagation in object [object MessageEvent]. (http://ajax.cloudflare.com/cdn-cgi/nexp/dokv=97fb4d042e/cloudflare.min.js#3)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:705)
    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.execute(JavaScriptEngine.java:591)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:566)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossible(HtmlPage.java:975)
    at com.gargoylesoftware.htmlunit.html.HtmlScript.executeInlineScriptIfNeeded(HtmlScript.java:349)
    at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:409)
    at com.gargoylesoftware.htmlunit.html.HtmlScript$3.execute(HtmlScript.java:274)
    at com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:288)
    at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:741)
    at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
    at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:701)
    at org.cyberneko.html.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1170)
    at org.cyberneko.html.HTMLTagBalancer.endElement(HTMLTagBalancer.java:1072)
    at org.cyberneko.html.filters.DefaultFilter.endElement(DefaultFilter.java:206)
    at org.cyberneko.html.filters.NamespaceBinder.endElement(NamespaceBinder.java:330)
    at org.cyberneko.html.HTMLScanner$ContentScanner.scanEndElement(HTMLScanner.java:3126)
    at org.cyberneko.html.HTMLScanner$ContentScanner.scan(HTMLScanner.java:2093)
    at org.cyberneko.html.HTMLScanner.scanDocument(HTMLScanner.java:920)
    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:965)
    at com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:247)
    at com.gargoylesoftware.htmlunit.html.HTMLParser.parseHtml(HTMLParser.java:193)
    at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:268)
    at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:156)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:468)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:342)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:407)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:392)
    at TestClass.submittingForm(TestClass.java:23)
    at TestClass.main(TestClass.java:39)


 == CALLING JAVASCRIPT ==

  function (b) {
      var c = b.source;
      c !== a && null !== c || "cf-tick" !== b.data || (b.stopPropagation(), d.length > 0 && d.shift()());
  }

======= EXCEPTION END ========
======= EXCEPTION END ========
======= EXCEPTION END ========

And I am also receiving several Warnings regarding cookies:

Jul 19, 2014 10:52:35 AM org.apache.http.client.protocol.ResponseProcessCookies processCookies
WARNING: Cookie rejected [lang="en", version:0, domain:., path:/, expiry:null] Illegal domain attribute "". Domain of origin: "www.firedrive.com"
Jul 19, 2014 10:52:35 AM org.apache.http.client.protocol.ResponseProcessCookies processCookies
WARNING: Cookie rejected [lang="en", version:0, domain:., path:/, expiry:null] Illegal domain attribute "". Domain of origin: "www.firedrive.com"
Jul 19, 2014 10:52:35 AM org.apache.http.client.protocol.ResponseProcessCookies processCookies
WARNING: Cookie rejected [lang="en", version:0, domain:., path:/, expiry:null] Illegal domain attribute "". Domain of origin: "www.firedrive.com"
Jul 19, 2014 10:52:35 AM org.apache.http.client.protocol.ResponseProcessCookies processCookies
WARNING: Cookie rejected [lang="en", version:0, domain:., path:/, expiry:null] Illegal domain attribute "". Domain of origin: "www.firedrive.com"

Editing JavaScript is not an option as I have no access to the host.

Any ideas/links are much appreciated, thanks!

silentbugs
  • 391
  • 3
  • 10
  • Maybe timing is the issue. Refer to my answer in this question: http://stackoverflow.com/questions/17843521 – Mosty Mostacho Jul 19 '14 at 15:15
  • I can't know if this is the issue, as my code throws the exception as soon as I initialize the HtmlPage element ( webClient.getPage(link) ), so anything beyond that is not executed. – silentbugs Jul 31 '14 at 18:22

0 Answers0