File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Soft Skills this week in the Jobs Discussion 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: 42913
    
  68
The HtmlPage.getFrameByName method looks promising.
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?