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

StackOverflow https://stackoverflow.com/questions/13210584

  •  30-07-2021
  •  | 
  •  

質問

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?

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top