【问题标题】:How to get the content of a specific iframe using HtmlUnit. Iframe doesn't have name but it has ID如何使用 HtmlUnit 获取特定 iframe 的内容。 iframe 没有名称但有 ID
【发布时间】:2016-01-28 04:20:53
【问题描述】:

我想使用 HtmlUnit 获取特定 iframe 的内容。从其中一篇文章 (HtmlUnit can't get the js / ajax added of IFRAME) 中,我了解到我可以使用此代码:

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

但问题是 iframe 没有名称。我试图访问的 iframe 没有名称。像这样的:

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

如何获取此场景中的内容?

【问题讨论】:

    标签: java ajax iframe htmlunit


    【解决方案1】:

    试试这个:

    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();
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-05
      • 1970-01-01
      • 2021-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-12
      相关资源
      最近更新 更多