Home » excel » excel – UPS Automated tracking clicking a button

excel – UPS Automated tracking clicking a button

Posted by: admin May 14, 2020 Leave a comment

Questions:

I want to visit webpage. Then enter a number in test box. I was able to do that.

after that I want to click on the Track Button. Any idea how can I click through vba?

I already tried below commands. Any idea how can i find id of the Track button?

ie.document.getElementByName("track.x").Click
ie.document.getElementByClass("button btnGroup6 arrowIconRight").Click

Lets say we enter the tracking number “1ZW2E2360449018801” and once I click that button, a new webpage opens. I want to click on “shipment Progress” bar and copy the table that appears. any suggestions?

How to&Answers:

This will get it done..

Sub test()
' open IE, navigate to the website of interest and loop until fully loaded
    Set ie = CreateObject("InternetExplorer.Application")
    my_url = "http://wwwapps.ups.com/WebTracking/track?loc=en_US"

    With ie
        .Visible = True
        .navigate my_url
        .Top = 50
        .Left = 530
        .Height = 400
        .Width = 400

    Do Until Not ie.Busy And ie.readyState = 4
        DoEvents
    Loop

    End With

' Enter a value in the "Number" text box
    ie.Document.getElementById("trackNums").Value = "1ZW2E2360449018801"

' Click the "Submit" button
    Set Results = ie.Document.getElementsByTagName("input")
    For Each itm In Results
        If InStr(1, itm.outerhtml, "Track", vbTextCompare) > 0 Then
            itm.Click
            exit for
        End If
    Next

' Click the "Shipment Progress" button
    Set Results = ie.Document.getElementsByTagName("h4")
    For Each itm In Results
        If InStr(1, itm.outerhtml, "Shipment Progress", vbTextCompare) > 0 Then
           itm.Click
           exit for
        End If
    Next

' Get the text from the "Shipment Progress Table" and assign to a variable
    tbltxt = ie.Document.getElementsByTagName("table")(4).innertext

    ' process the text as desired
End Sub

Answer:

Something like this should work:

ie.document.getElementsByName("track.x")(0).Click

Note it’s getElement*s*ByName, so it returns a collection, not a single element.