WebBrowser控件文档属性未找到getElementById [英] WebBrowser Control document property not finding getElementById

查看:121
本文介绍了WebBrowser控件文档属性未找到getElementById的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该网页包含许多iframe。 在webbrowser_LoadComplete事件之后,我尝试按ID,按名称和按TagName查找元素。 如果iframe上存在该元素,我找不到它。 我在wpf表单上有一个按钮,我可以等到所有iframe都已呈现。 我是否需要分别搜索iframe?


HTMLDocument

The page has many iframes.  After the webbrowser_LoadComplete event I tried to find elements by ID, by name, and by TagName.  If the element exists on the iframe I can't find it.  I have a button on the wpf form and I can wait until all iframes have rendered.  Do I need to search the iframes separatly?

HTMLDocument

 

d =( HTMLDocument 。 webBrowser1.Document;
//找到框架(作品)
IHTMLElement id = d.getElementById( " frame1" );
//查找div不起作用 IHTMLElementCollection ec = d.getElementsByTagName( " div" ); foreach IHTMLElement e ec)
{
if (e.className!= null
{
if (e.className.ToString()== " CassA"
....从未找到ClassA。
如果将div放在没有iframe的页面上,则可以正常工作。

d = (HTMLDocument)this.webBrowser1.Document;
//Find the frame (works)
IHTMLElement id = d.getElementById("frame1");
//Find the div does not work
IHTMLElementCollection ec = d.getElementsByTagName("div");
foreach (IHTMLElement e in ec)
{
if (e.className != null)
{
if (e.className.ToString() == "CassA")
....
never finds ClassA.
If the place the div on a page without an iframe it works.

推荐答案


嗨JW Grant,

请试试以下在iframe中搜索div标签的方法:

HtmlDocument d =( HtmlDocument .webBrowser1.Document;

IHTMLElementCollection = d.Window.Frames [index] .Document .GetElementsByTagName(" div");


最好的问候,
Guang-Ming Bian - MSFT
MSDN订阅者支持
在论坛中 如果您对我们的支持有任何反馈意见,请联系 msdnmg@microsoft.com


这篇关于WebBrowser控件文档属性未找到getElementById的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆