Unable to cast COM object of type 'System.__ComObject' to interface type 'mshtml.HTMLElementCollection

白昼怎懂夜的黑 提交于 2019-12-23 05:06:00

问题


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")

but i get the following error

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?


回答1:


Dim buttons As MSH.HTMLElementCollection

Wrong type. That should be an IHTMLElementCollection instead. Note the leading I. The MSDN page is here.

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.



来源:https://stackoverflow.com/questions/13210584/unable-to-cast-com-object-of-type-system-comobject-to-interface-type-mshtml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!