当我使用getAttribute时,返回System .__ ComObject [英] System.__ComObject is returned when I use getAttribute

查看:56
本文介绍了当我使用getAttribute时,返回System .__ ComObject的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行以下代码:

HtmlElement.GetAttribute("onClick")

尝试访问该元素的onClick属性,但返回的所有内容都是System .__ ComObject.我不知道为什么会这样,所有其他GetAttribute调用都返回实际的字符串.

To try and get access to the onClick attribute of that element, but all this returns is System.__ComObject. I don't know why this happens, all other GetAttribute calls return the actual string.

谢谢.

推荐答案

首先,您可以尝试确定控件的类型.然后将您的对象投射为这种类型.使用此方法可以访问元素的属性.

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.

例如,如果您的对象是"div"包含"onclick"方法,则必须将com对象转换为 mshtml.HTMLDivElement (必须将程序集"mshtml.dll"添加到您的使用mshtml类的项目);那么您可以在 outerHTML 属性中查找"onclick"属性.

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];
    }

这篇关于当我使用getAttribute时,返回System .__ ComObject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆