0

I'm using HTMLunit to fill out a form on a site, but get stuck on an HTMLanchor which needs to submit it.

the html code:

<a id="syi-place-ad-button" class="button primary medium  "><span>Plaats uw advertentie</span></a>

trying to click it:

    HtmlAnchor submitButton = (HtmlAnchor) page2.getElementById("syi-place-ad-button");     
    form2.appendChild(submitButton);
     
    page3 = submitButton.click();;
    webClient.waitForBackgroundJavaScript(10*1000);
    webClient.setAjaxController(new NicelyResynchronizingAjaxController());
    
    WebResponse response = page3.getWebResponse();
    String content = response.getContentAsString();
    System.out.println(content);
    webClient.closeAllWindows();

gives this error in the end:

== CALLING JAVASCRIPT ==

  function (e) {
      return st === t || e && st.event.triggered === e.type ? t : st.event.dispatch.apply(s.elem, arguments);
  }

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

can anyone help me on my way to what I might be missing or doing wrong here?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
  • Looks like the [same old JavaScript](http://stackoverflow.com/questions/20315330/how-to-overcame-htmlunit-scriptexception) issue to me – Mosty Mostacho Jan 04 '14 at 14:38
  • Thanks, i looked at the answer there. but the options given there didn't help me. so if anyone has any ideas on a way to fix this? – user3160167 Jan 04 '14 at 15:33

2 Answers2

0

Can you stop the javascript running in background and let me know the result.Stop the JS as bellow

client.setJavaScriptEnabled(false);
Paul Richter
  • 10,908
  • 10
  • 52
  • 85
Kick
  • 4,823
  • 3
  • 22
  • 29
  • setJavaScriptEnabled() is not a function in the newer htmlunits anymore. so i cant use that :( – user3160167 Jan 07 '14 at 20:02
  • the result i get is that no changes happened to the page. the page i get after the click is the same as before the click. so a click doesn't seem to be invoked :( – user3160167 Jan 08 '14 at 12:06
  • Can you run below code and let me know: HtmlElement submitButton = page2.getElementById("syi-place-ad-button"); page3 = (HtmlPage)submitButton.click(); – Kick Jan 08 '14 at 12:40
  • same thing. no change. the page before the click is has no changes to the page after click. as if no click happened. – user3160167 Jan 08 '14 at 13:06
  • The form source is too big to post here i guess, but you should be able to get to the URL very simple: https://www.marktplaats.nl/syi/plaatsAdvertentie.html then you have to click 3 options under 1st: Kleding | Dames 2nd: Schoenen en Beenmode 3rd: Schoenen after clicking the 3rd you'll get on the page wich im trying to fill the form on. – user3160167 Jan 08 '14 at 13:48
  • I can't operate the form bcoz language is other than english.But i have noticed that anchor element which need to click is disabled initially so make sure that anchor is enabled before click through htmlunit otherwise it will not make any change in page. – Kick Jan 08 '14 at 17:17
  • yeah it is diabled because you need to login. i already managed to login before hand. so the moment i try the click it shows as enabled. – user3160167 Jan 08 '14 at 21:04
  • kk,I dont found the HREF attribute in anchor so when its enable then HREF attribute exist ? – Kick Jan 09 '14 at 06:14
0

Although setJavaScriptEnabled(boolean) was deprecated in 2.13 it was added to the WebClientOptions member of the WebClient. Here is the doc.

In order to disable JavaScript you should do this:

webClient.getOptions().setJavaScriptEnabled(false);

Kick
  • 4,823
  • 3
  • 22
  • 29