当我尝试获取时,为什么 HtmlElement
的 GetAttribute()
方法返回 mshtml.HTMLInputElementClass
而不是属性的值表单的 action
属性的值?
HtmlElementCollection elements = webBrowser1.Document.Forms;
foreach (HtmlElement element in elements)
MessageBox.Show(element.GetAttribute("action") + "");
最佳答案
这似乎是一个 IE 错误。
这是一个解决方案:添加对 Microsoft.mshtml 的引用,然后:
if(element.GetAttribute("action").Equals("mshtml.HTMLInputElementClass"))
{
mshtml.IHTMLFormElement iForm = (mshtml.IHTMLFormElement)element.DomElement;
string action = iForm.action;
}
希望这有帮助:)
关于c# - 为什么 HtmlElement 的 GetAttribute() 方法返回 "mshtml.HTMLInputElementClass"而不是属性的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3805226/