drec4s
drec4s

Reputation: 8077

Accessing DispHTMLElementCollection properties

I need to iterate through the elements of an object that (as the debugger states) is a DispHTMLElementCollection.

Can't seem to be able to access the properties of a DispHTMLElementCollection as there is a table with 50 td tags on this page, and when I print out the length of this object it returns 0.

Any light about this is appreciated.

Thanks.

EDIT:

Using this snippet, you still need to break the code to press the search button to show some results, but after that, still returns zero as length...

Dim objHTML As HTMLDocument

Set ie = New InternetExplorer
With ie
    .navigate "https://www.oeko-tex.com/en/manufacturers/certified_products/certified_products.html"
    .Visible = True
    While .Busy Or .readyState <> READYSTATE_COMPLETE
       DoEvents
    Wend
    Set objHTML = .document
    DoEvents
End With
Set elementONE = objHTML.getElementsByTagName("td")
Debug.Print TypeName(elementONE)
Debug.Print elementONE.Length

Upvotes: 0

Views: 2963

Answers (1)

user5412293
user5412293

Reputation:

Using the feedback from Tim Williams

Sub test()

    Dim objHTML As HTMLDocument
    Dim ie As InternetExplorer
    Dim oElemets As Object
    Dim oElement As Object

        Dim h As HTMLOptionElementFactory
    Set ie = New InternetExplorer
    With ie
        .navigate "https://www.oeko-tex.com/en/manufacturers/certified_products/certified_products.html"
        .Visible = True
        While .Busy Or .readyState <> READYSTATE_COMPLETE
            DoEvents
        Wend
        Set objHTML = .document
        DoEvents
    End With

    ' As per the suggestion Tim Williams proposed
    Set objHTML = objHTML.getElementById("customer-profile")
    Set oElemets = objHTML.getElementsByTagName("td")


    For Each oElement In oElemets
        Debug.Print oElement.nodeName
    Next

End Sub

Thanks

Upvotes: 1

Related Questions