2010-09-27 84 views
2

为什么HtmlElementGetAttribute()方法返回mshtml.HTMLInputElementClass而不是属性的值,当我试图获取表单的action属性的值?为什么HtmlElement的GetAttribute()方法返回“mshtml.HTMLInputElementClass”而不是属性值?

HtmlElementCollection elements = webBrowser1.Document.Forms; 
    foreach (HtmlElement element in elements) 
     MessageBox.Show(element.GetAttribute("action") + ""); 
+0

没有摄制。发布显示表单的HTML。 – 2010-09-27 16:29:41

+0

可以工作的示例:http://www.w3schools.com/TAGS/tryit.asp?filename=tryhtml_form_submit – 2010-09-27 16:30:33

+0

http://amazines.com/member_login.cfm – luvieere 2010-09-27 16:40:11

回答

3

这似乎是一个IE错误。

这里是一个解决方案:添加引用Microsoft.mshtml,则:

if(element.GetAttribute("action").Equals("mshtml.HTMLInputElementClass")) 
{ 
    mshtml.IHTMLFormElement iForm = (mshtml.IHTMLFormElement)element.DomElement; 
    string action = iForm.action; 
} 

希望这有助于:)

+0

谢谢,它完成了工作! – luvieere 2010-10-24 14:22:44

相关问题