This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread 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 Android Security Essentials Live Lessons this week in the Android 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: 41182
    
  45
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get at frames using HtmlUnit?
 
Similar Threads
ADF MyFaces and HttpUnit testing
Not able to retrieve data for Secured site
regex help
RequestDispatcher.forward problem
"print this page" link (for frames pages)