开发者

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

开发者 https://www.devze.com 2023-01-17 14:37 出处:网络
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

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

精彩评论

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