3

I'm using HtmlUnit to load a webpage full of JavaScript. The WebClient executes the JavaScript just fine.

However, when I click a button on a particular form that invokes an Ajax call, even though the call itself completes, the content (result) does not appear on the page (even though it does in a real browser).

Why doesn't the HtmlPage contain the dynamically added content after I click the button?

Is there a way to get an "updated" page in HtmlUnit?

user2103849
  • 551
  • 6
  • 17
  • 1
    When you say the call completes, do you mean the call that executes the AJAX request or the response callback? My guess is you might be checking for the content before the AJAX request returns. Any code? – NG. Aug 04 '13 at 02:06
  • 2
    HtmlUnit will execute the Ajax call and **will** update the page. Just observe that, unlike a regular page loading, the `click()` call will **not** wait for the completion of the Ajax request. It will proceed to the next line of code right away. – acdcjunior Aug 04 '13 at 02:12
  • Without code, we can't tell what you've tried, but here's another question that explains how to wait for an Ajax request to complete: http://stackoverflow.com/questions/5555178/htmlunit-doesnt-wait-for-javascript – FThompson Aug 04 '13 at 02:20
  • i think i'll be able to solve this problem in a different way. thanks for your help – user2103849 Aug 04 '13 at 02:27

1 Answers1

0

First you have to wait for completion of AJAX call, then it requires synchronization of your page after Ajax call,

    synchronized (your_page);
Tasawer Nawaz
  • 927
  • 8
  • 19