1

I am trying to use HtmlUnit to make HTML snapshot of my GWT application. The idea is to make my AJAX app crawlable.

Unfortunately, the page I'm fetching doesn't seem complete. It is missing content which is viewable when I visit the page in my normal browser. I only need text in my HTML snapshot. Here is my code:

public class Browser {

    public static void main(String[] args) throws IOException, InterruptedException {

       final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_10);
        webClient.setJavaScriptEnabled(true);//JS is enabled by default but...
        webClient.setAjaxController(new NicelyResynchronizingAjaxController());

        HtmlPage page = webClient.getPage("http://meridianbet.com");

        int n = webClient.waitForBackgroundJavaScript(30000);

        System.out.println("Executing " + n + " JavaSript jobs!");

        System.out.println("OUTPUT: " + page.asXml());
        webClient.closeAllWindows();
       }
}

There is still 7 unfinished JS jobs after executing code. And no matter how long I wait that jobs ain't gonna be executed. Any help? //I am using latest htmlunit 2.10

Sicco
  • 6,167
  • 5
  • 45
  • 61
Manijak
  • 51
  • 4

1 Answers1

0

I am running into a similar problem. Have you tried using a loop like this:

while (i > 0)
        {
            i = webClient.waitForBackgroundJavaScript(1000);

            if (i == 0)
            {
                break;
            }
            synchronized (page) 
            {
                System.out.println("wait");
                page.wait(500);
            }
        }

When I use a loop like this, it just sits there and says: "wait" indefinitely. But perhaps it will work for you.

If you do solve your problem, make sure you post what you did, because I think it will solve my same problem.

I found that code on this question: HTMLUnit doesn't wait for Javascript

Community
  • 1
  • 1
Meeks
  • 21
  • 1
  • 1
  • 3
  • I tried that already. And I get infinite loop, becouse there is unfinished JavaScript jobs. Problem is that I am getting anchor closing tag on the wrong place. – Manijak Sep 24 '12 at 12:51
  • This is what I get and this is what I get whit regular browser . Since I didn't find solution, I'm correcting that manually. – Manijak Sep 24 '12 at 13:05