开发者

Why does HtmlElement's GetAttribute() method return "mshtml.HTMLInputElementClass" instead of the attribute's value?

Why does HtmlElement's GetAttribute() method return mshtml.HTMLInputElementClass instead of the attribute's value, when I'm trying to obtain the value of a form's action attr开发者_如何学运维ibute?

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


It seems to be an IE bug.

Here is a solution : add a reference to Microsoft.mshtml, then :

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

Hope this help :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜