This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Testing and the fly likes How to get at frames using HtmlUnit? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "How to get at frames using HtmlUnit?" Watch "How to get at frames using HtmlUnit?" New topic
Author

How to get at frames using HtmlUnit?

Andrew Och
Ranch Hand

Joined: Mar 19, 2004
Posts: 32
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
Marshal

Joined: Mar 22, 2005
Posts: 41592
    
  55
The HtmlPage.getFrameByName method looks promising.


Ping & DNS - my free Android networking tools app
Andrew Och
Ranch Hand

Joined: Mar 19, 2004
Posts: 32
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

Joined: Mar 19, 2004
Posts: 32
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to get at frames using HtmlUnit?