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:
<code>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);
}
}
});</code>
<code>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.