![](/img/trans.png)
[英]Get current / computed style of an HtmlElement in WebBrowser control
[英]Unable to get htmlelement in winforms webbrowser control
我正在使用Winforms Webbrowser控件开发自动化程序。 我能够在前几个网页上获得htmlelement。 但是我无法从某些页面获取htmlelement,并且我正在使用与前几个Web页面相同的方法(成功获取了前几个htmlelement)。
HtmlElement createButton = this.extendedWebBrowser2.Document.GetElementById("createButton");
HtmlElement textArea = this.extendedWebBrowser2.Document.GetElementById("query");
HtmlElement filename = this.extendedWebBrowser2.Document.GetElementById("filename");
HtmlElement cancelBtn = this.extendedWebBrowser2.Document.GetElementById("cancelBtn");
它返回null,尽管这些元素存在于页面中,我也不知道为什么它返回null。 为什么以及该怎么做才能检测到html元素? 什么样的原因会导致其无法检测?
很久以前,当我最后一次尝试使用Web浏览器控件时,但是在旧版本的.net中,有一种方法可以使用这种方式:
HtmlElement createButton = this.extendedWebBrowser2.Document.Body.GetElementById("createButton");
公告Body
。
也许有帮助吗?
if (objBrowser.Document.Window != null) {
foreach (HtmlWindow myframe in objBrowser.Document.Window.Frames) {
HtmlElementCollection htmlControls = myframe.Document.Body.GetElementsByTagName("OPTION");
foreach (HtmlElement optEle in htmlControls) {
optEle.SetAttribute("selected", "true");
}
}
}
无法获取HTML元素的原因是因为HTML元素嵌入在FrameSet中。 要访问FrameSet:
HtmlWindow docWindow = extendedWebBrowser2.Document.Window;
foreach (HtmlWindow frameWindow in docWindow.Frames)
{
implementation code...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.