davidbayonchen
davidbayonchen

Reputation: 121

internetexplorer.application object - getting item by class

I am using VBA to open a web page and need to collect the value of some elements that have a specific class.

With CreateObject("internetexplorer.application")
    .Visible = True
    .Navigate "http://www.google.com"
    While .ReadyState <> 4 Or .Busy
        DoEvents
    Wend
    Set r = .document.getelementsbyclassname("gssb_f")
    ' REST OF CODE
End With

The above does not work.

I am also struggling to find a library of all available properties and methods for the InternetExplorer.Application object. Does it exist?

Upvotes: 2

Views: 5451

Answers (3)

QHarr
QHarr

Reputation: 84465

You can now use .querySelectorAll method of document to apply a CSS selector of

.gssb_f

The "." means className. This method returns a nodeList which you can loop over by traversing the .Length of the returned nodeList.

Syntax:

.document.querySelectorAll(".gssb_f")

Upvotes: 1

PermaNoob
PermaNoob

Reputation: 869

I was just searching for a workaround for this and could only find this. I'm posting an example of the idea @davidbeyonchen had in case anyone else has this issue. I was only searching for one item, but it could be modified to include multiple items.

For Each elem In .Document.all
    If elem.className = "gssb_f" Then
        Set r = elem
        Exit For
    End If
Next

Upvotes: 0

supersophisticated
supersophisticated

Reputation: 127

In the VBA Editor, you should try to add references to 'Microsoft Internet Controls'. Click on 'Tools' > 'References' > Check 'Microsoft Internet Controls' > Click OK.

My guess is this should work.

-Nin

Upvotes: 0

Related Questions