Example I

Accessing the page enclosed inside a <frame> or <iframe> element can be done by calling HtmlPage.getFrames().

Suppose you have the following HTML page:

<html>
  <body>
    <iframe src="two.html"></iframe>
  </body>
</html>

You can use the following code to retrieve the content of two.html:

final List<FrameWindow> window = page.getFrames();
final HtmlPage pageTwo = (HtmlPage) window.get(0).getEnclosedPage();

Example II

The following example navigates API documentation frames to access a specific class page:

final WebClient client = new WebClient();
final HtmlPage mainPage = client.getPage("https://www.htmlunit.org/apidocs/index.html");

To access the page in the first frame (upper left) and click the sixth link:

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

To access the page in the frame named packageFrame (lower left) and click the second link:

final HtmlPage packagePage = (HtmlPage) mainPage.getFrameByName("packageFrame").getEnclosedPage();
packagePage.getAnchors().get(1).click();

To access the page in the frame named classFrame (right main pane):

final HtmlPage classPage = (HtmlPage) mainPage.getFrameByName("classFrame").getEnclosedPage();