0

I want to get the content of a specific iframe using HtmlUnit. From one of the post (HtmlUnit can't get the js / ajax added of IFRAME) I got an idea that I can use this code:

HtmlPage currentPage = (HtmlPage)webClient.getWebWindowByName("Frame Name").getEnclosedPage();

But the issue is that iframe doen't have name. The iframe which i am trying to access have id not name. Something like this:

<iframe class="text" id="frameContent" style="width:548px;" frameborder="0" src="" tabindex="-1" allowtransparency="true" scrolling="no" height="210"></iframe>

How to get the content in this scenario?

Community
  • 1
  • 1
Shashank
  • 712
  • 15
  • 33

1 Answers1

1

Try this:

HtmlPage page = client.getPage("http://example.com/");
List<FrameWindow> frames = page.getFrames();
for (FrameWindow frame : frames) {
    if (frame.getFrameElement().getId().equals("frameContent")) {
        page = (HtmlPage) frame.getEnclosedPage();
    }
}
haihui
  • 1,075
  • 1
  • 18
  • 25