I want to run the onclick javascript function, on the html code shown below, with java and HtmlUnit and get the info that the scripts produce.
<td width="13"><a class="img_attachfile16" alt="show files" title="show files" rel="Hide files" href="#" onclick="return (DocumentFiles.ShowHideFiles(12, 345234, 0, this))"></a></td>
What function ShowHideFiles do is that when you click on the link it will show you names of files(in the table cell) that can be downloaded and their urls. I want to get this information with java and HtmlUnit but i cant get it to work. This is what i've tried:
webClient = new WebClient(BrowserVersion.FIREFOX_17);
HtmlPage page = webClient.getPage(url);
List tables = page3.getByXPath("//table");
//Get the right table
HtmlTable table = (HtmlTable) tables.get(11);
List<HtmlTableCell> cells = tableRow.getCells();
//Get the right cell and its childelement(where the onclick function is).
HtmlElement element = cells.get(10).getFirstElementChild();
String clickAttr = element.getOnClickAttribute();
ScriptResult scriptResult = page.executeJavaScript(clickAttr);
//Get new page
HtmlPage page2 = (HtmlPage) scriptResult.getNewPage();
System.out.println(page2.asXml());
The new page i get is the same as before, meaning that i don't see the extra info i want. I've also tried to execute the click from the HtmlElement like this:
//Same as before but now make HtmlAnchor object from right cell
HtmlAnchor anchor = (HtmlAnchor) cells.get(10).getFirstElementChild();
page2 = (HtmlPage) anchor.click();
System.out.println(page2.asXml());
Like with previous try the new page i get is same as before with no extra info.
I would really appreciate suggestions on how to solve this.
Best regards /Tomas
I added this lines:
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
//This one after getNewPage()
webClient.waitForBackgroundJavaScript(1000);
No changes in the new retrieved page now either. How do i get the error logs? I don't get any exceptions. What more can i do?