System.__ComObject is returned when I use getAttribute

后端 未结 2 1599
北荒
北荒 2020-12-22 06:38

I am running this code:

HtmlElement.GetAttribute(\"onClick\")

To try and get access to the onClick attribute of that element, but all this

2条回答
  •  一生所求
    2020-12-22 07:13

    First, you can try to determine type of the control; then cast your object to this type. Accessing properties of element is possible with this method.

    For example, if your object is a "div" contains an "onclick" method, you must convert your com object to mshtml.HTMLDivElement (You must add assembly "mshtml.dll" into your project for using mshtml class); then you can look for "onclick" attribute in outerHTML property.

        if (doc.GetElementById("id-of-div").GetAttribute("onclick").Equals("System.__ComObject"))
        {
                mshtml.HTMLDivElement docCOM = (mshtml.HTMLDivElement)doc.GetElementById("id-of-div").DomElement;
    
                string onClickStr = docCOM.outerHTML.[some string or regex operations here];
        }
    

提交回复
热议问题