2 Replies Last post: Aug 28, 2008 5:47 PM by Vladimir Ikryanov  
hegh   7 posts since
Aug 15, 2008
Currently Being Moderated

Aug 19, 2008 7:52 PM

How to get the the content of a page developed by ajax?

 

Two pages(page a, page b) are developed by ajax and use the same url.

By clicking a button on page a, you can navigate to page b. How can you get the page b's content after

firing onclick event on page a by using addNavigationListener or other eventListener?

 

Here is an example. The source-code is below:

 

 

WebBrowser browser = new IEAutomation();

((IEAutomation)browser).setVisible(true);

browser.navigate("http://www.giannifrey.com/ajax/news.html");

browser.waitReady();

Thread.sleep(5000);

HTMLElement element = (HTMLElement)browser.getDocument().getElementById("btn_next");

element.click();

browser.addNavigationListener(new NavigationEventAdapter() {

public void documentCompleted(WebBrowser webBrowser, String url) {

    System.out.println(url);

    String c = webBrowser.getContent();

    //to find whether the browser has loaded the second article' content(contains "willkommen").

    //if loaded, print it.

if (c.contains("willkommen")) {

      System.out.println(c);

    }

}

});I use NavigationEventAdapter in the above code, but I can never prints the second article's content.

Here supplies some additional information:

1.The site http://www.giannifrey.com/ajax/news.html is developed by ajax.I think this is very important.

2.I use Thread.sleep(5000) to load the first page's content into browser and then I can

click on the button ">"(represents by the id:btn_next) to navigate to the page that

shows the second article's content.

3.All the pages in this site uses the same url.This is also very important.

Would you please do me a favor to print the second article's content not by using "Thread.sleep()" but by using addNavigationListener or other eventListener?I also supply the java file of the code in attached files.

 

 

Attachments:
Vladimir Ikryanov TeamDev Ltd. 404 posts since
Apr 24, 2006
Currently Being Moderated
1. Aug 28, 2008 5:47 PM in response to: hegh
Re: How to get the the content of a page developed by ajax?

Hi,

 

Further discussion of this thread you can find here: http://support.teamdev.com/thread/2374?tstart=0

 

Regards,

Vladimir Ikryanov

Vladimir Ikryanov TeamDev Ltd. 404 posts since
Apr 24, 2006
Currently Being Moderated
2. Aug 28, 2008 5:47 PM in response to: hegh
Re: How to get the the content of a page developed by ajax?

Hi,

 

Further discussion of this thread you can find here: http://support.teamdev.com/thread/2374?tstart=0

 

Regards,

Vladimir Ikryanov

More Like This

  • Retrieving data ...