UPS Automated tracking clicking a button

社会主义新天地 提交于 2019-12-07 03:06:27

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!