This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get at frames using HtmlUnit?

 
Andrew Och
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using HtmlUnit to test a website.

My problem is that the first page returns a set of frames.

// Get the web page from the URL
final HtmlPage framePage = (HtmlPage) webClient.getPage(url);
System.out.println(framePage.asXml);

prints a page with 3 frames and I want to work on the main frame.

How do I get that main frame as an HtmlPage?


Sigh I am stupid.
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The HtmlPage.getFrameByName method looks promising.
 
Andrew Och
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have played with getFrameByName and getFrames. What I am after is the web page inside these frames.

I wish something like this would work:
HtmlPage mainPage = (HtmlPage) myPage.getFrameByName("mainframe").getPage();

but getFrameByName() returns a FrameWindow object which I dont know how to use and in my case specifically the contents are printed out I have:
<frame src="ident.asp" noresize="" name="mainframe" target="_top" border="0">

Which is just one part of myPage.
 
Andrew Och
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Ulf

You are absolutely correct, and I am just a muppet.

HtmlPage.getFrameByName("mainframe")

followed by

FrameWindow.getEnclosedPage()

Gives me the HtmlPage that I am after.

Thank you very much for your help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic