WebBrowser控件文档属性未找到getElementById [英] WebBrowser Control document property not finding 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; d = (HTMLDocument)this.webBrowser1.Document; 嗨JW Grant, HtmlDocument d =( HtmlDocument ) 此 .webBrowser1.Document; IHTMLElementCollection = d.Window.Frames [index] .Document .GetElementsByTagName(" div"); 这篇关于WebBrowser控件文档属性未找到getElementById的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
//找到框架(作品)
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的页面上,则可以正常工作。
//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.推荐答案
请试试以下在iframe中搜索div标签的方法:
最好的问候,
Guang-Ming Bian - MSFT
MSDN订阅者支持 在论坛中 如果您对我们的支持有任何反馈意见,请联系 msdnmg@microsoft.com