【问题标题】:click on element inside of iFrame单击 iFrame 内的元素
【发布时间】:2017-11-08 22:22:44
【问题描述】:

我的内置浏览器下载了一个页面。
在此页面的“body”下,有一个“iframe”标签。
在这个 iframe 内部,还有另一个代码(div 标签、表格等)。
但我不知道如何访问它们。

webBrowser1.Document.GetElementById("myiFrame").innerHTML // gives out empty result as if there is nothing there.
webBrowser1.Document.GetElementById("myiFrame").FirstChild.innerHTML // gives an error as if there is no first child.
webBrowser1.Document.GetElementById("mylink") // error as if it doesn't exist
webBrowser1.Document.GetElementsByTagName("a")[2] // error as if it doesn't eist

我没有选择。

我需要点击这个框架深处的一个东西:

body -> div -> div -> div -> form -> div -> div -> div -> div -> div -> div -> div -> div -> table -> tbody -> tr -> td -> a

【问题讨论】:

  • 当您说“GetElementsByTagName”不起作用时 - 您的意思是 document.GetElementsByTagName 不起作用?因为如果你做整个文档,它应该会找到它。

标签: c# html browser webbrowser-control


【解决方案1】:

确实 Document.InvokeScript([whatever it is you want to click]

工作?

您确定它已全部下载吗? Webbrowser.ReadyState 为每一帧触发 Ready。

【讨论】:

  • 我确定该元素已下载,因为 1) 我在屏幕上看到它; 2) Firefox 中的 Firebug 确实可以看到它(事实上,这是查看 html 的唯一方法,例如 View Source 没有看到它)。
【解决方案2】:

您应该加载显示在 iframe 中的页面,而不是加载父页面并浏览它。您可以获取 iframe 的 src 属性并导航到页面。这样您就可以轻松访问需要访问的节点。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-20
    • 2020-05-24
    • 1970-01-01
    • 1970-01-01
    • 2019-06-01
    • 2016-09-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多