How to use getElementsByClassName on an Internet Explorer object in VB.Net?

1

I'm trying to use a getElementsByClassName in an Access macro. You're experiencing an error on the line:

If ie.Document.GetElementsByClassName("msgErroAdic").Length > 1 Then

Being Dim ie as Object and Set ie = CreateObject("InternetExplorer.Application") Returns the error that the method can not find. I found this site: link
There is no GetElementsByClassName method in the InternetExplorer object. However, on this other site: link there is the GetElementsByClassName .

I would like to know the difference.

I also saw other issues where they indicate creating a function, but it did not work either. Public Function GetElementsByClassName(Source As HtmlDocument, ClassName As String) As HtmlElement() Compile error: "The user-defined type has not been defined".

    
asked by anonymous 17.04.2017 / 18:59

1 answer

0

FromtheReferencesmenu,youshouldenable:

  • MicrosoftInternetControls
  • MicrosoftHTMLObjectLibrary

Thecodebelowwasthebasisforsolvingtheproblem.ThesecretisthattheGetElementsByClassNamepropertyisonlyforHTMLelements,soitwasnecessarytosettheobjecttoHTMLDocumentbeforeusingGetElementsByClassName

PublicSubnavegar()DimieAsSHDocVw.InternetExplorerDimhtmlAsHTMLDocumentDimelementosAsObjectDimitemAsObjectSetie=NewInternetExplorerie.Visible=Falseie.Navigate"https://pt.stackoverflow.com/"

Do While ie.ReadyState <> READYSTATE_COMPLETE
    DoEvents
Loop

Set html = ie.Document
Set elementos = html.getElementsByClassName("horizontal-manchete")

For Each item In elementos
    Debug.Print Trim(item.innerText) & vbCrLf
Next

MsgBox "Fim"

ie.Quit
Set ie = Nothing

End Sub

I hope I have helped.

    
19.04.2017 / 17:56