Search code examples
javahtmlhtmlunit

HtmlUnit - Get returned information


I am struggling with the last part of my project in regards to HtmlUnit. I have succesfully managed to fill out the form details and click the submit button but this returns me a page object

Page submitted = button.click();

The API for page interface can be found here - http://htmlunit.sourceforge.net/apidocs/com/gargoylesoftware/htmlunit/Page.html . I have spent a while trawling through the API to try and see how, based on the returned page after clicking the button I can then access the html table on the resulting page.

Would anyone be able to help me with the appropriate methods calls I would need to use in order to complete this.

Thanks


Solution

  • If the page returned is truly HTML (and not, for instance, a zip file) you can do this:

    HtmlPage htmlPage = (HtmlPage) button.click();
    DomNodeList<HtmlElement> nodes = htmlPage.getElementsByTagName("table");
    ...
    HtmlTable table = getTheTableIWant(nodes);
    doSomethingWith(table);