如何使用 htmlunit 驱动程序访问嵌入式 iframe 元素?

How to access embedded iframe elements with htmlunit driver?

我想使用 com.gargoylesoftware.htmlunit.WebClient 访问嵌入式 iframe 的内部内容:

<html>
<body>
<iframe...>
    #document
    <html>
    <body>
        ...
        <input name="myinput" />
    </body
</iframe>
</body>
</html>

我已经可以通过以下方式获取 iframe

HtmlInlineFrame iframe = (HtmlInlineFrame) page.getElementsByTagName("iframe").get(0);

现在我想抓取输入元素。但即使列出任何 input 元素也只显示一个空列表:

NodeList inputs = iframe.getElementsByTagName("input");

那么这里可能出了什么问题?如何访问 embedded iframe 的内部?

尝试

HtmlInlineFrame iframe = (HtmlInlineFrame) page.getElementsByTagName("iframe").get(0);
HtmlPage innerPage = (HtmlPage) iframe.getEnclosedPage();
NodeList inputs = innerPage.getElementsByTagName("input");