无法将“System.__ComObject"类型的 COM 对象转换为接口类型“mshtml.HTMLElementCollection"
我正在尝试使用 mshtml 通过 webbrowser 控件在 vb.net 上填写表单,
Am trying to use mshtml to fill a form on vb.net through the webbrowser control,
Dim doc As MSH.IHTMLDocument2 = DirectCast(wbMain.Document.DomDocument, MSH.IHTMLDocument2)
Dim buttons As MSH.HTMLElementCollection = doc.getElementsByTagName("button")
Dim Inputs As MSH.HTMLElementCollection = doc.getElementsByTagName("input")
但我收到以下错误
无法将类型为System.__ComObject"的 COM 对象转换为接口输入mshtml.HTMLElementCollection".此操作失败,因为QueryInterface 调用具有 IID 的接口的 COM 组件{3050F56B-98B5-11CF-BB82-00AA00BDCE0B}"由于以下原因失败错误:不支持此类接口(来自 HRESULT 的异常:0x80004002(E_NOINTERFACE)).
Unable to cast COM object of type 'System.__ComObject' to interface type 'mshtml.HTMLElementCollection'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{3050F56B-98B5-11CF-BB82-00AA00BDCE0B}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
谁能帮我解决可能的解决方案?
can anyone help me out with the possible solution?
将按钮调暗为 MSH.HTMLElementCollection
Dim buttons As MSH.HTMLElementCollection
类型错误.那应该是一个 IHTMLElementCollection .注意前面的 I.MSDN 页面 在这里.
Wrong type. That should be an IHTMLElementCollection instead. Note the leading I. The MSDN page is here.
缺少 I 的类型是 coclass,而不是接口.由脚本客户端在想要创建自己的集合对象时使用.
The type that is missing the I is a coclass, not an interface. Used by scripting clients when they want to create their own collection object.