我想使用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");