Skip to content Skip to sidebar Skip to footer

Htmlunit Unable To Get Frame Content

I am trying to set the value of a search box, to click a search button and to parse the results. The problem is that the results are displayed in another frame and I am not able to

Solution 1:

You may try to get that frame using next code:

HtmlPageframePage= (HtmlPage)pageAfterLogin.getFrameByName("your_frame_name").getEnclosedPage();

After getting source of the frame you may get html elements (like you did on login page) inside this page.

Solution 2:

You can try this example (taken from http://htmlunit.sourceforge.net/frame-howto.html)

finalWebClientclient=newWebClient();
finalHtmlPagemainPage= client.getPage("http://htmlunit.sourceforge.net/apidocs/index.html");

To get the page of the first frame (at upper left) and click the sixth link:

final HtmlPage packageListPage = (HtmlPage) mainPage.getFrames().get(0).getEnclosedPage();
packageListPage.getAnchors().get(5).click();

To get the page of the frame named 'packageFrame' (at lower left) and click the second link:

finalHtmlPagepakcagePage= (HtmlPage) mainPage.getFrameByName("packageFrame").getEnclosedPage();
pakcagePage.getAnchors().get(1).click();

To get the page of the frame named 'classFrame' (at right):

finalHtmlPageclassPage= (HtmlPage) mainPage.getFrameByName("classFrame").getEnclosedPage();

Post a Comment for "Htmlunit Unable To Get Frame Content"