UPS自动跟踪单击按钮

时间:2014-04-02 19:14:14

标签: excel vba excel-vba click

我想访问webpage。然后在测试框中输入一个数字。我能够做到这一点。

之后我想点击Track Button。不知道如何点击vba?

我已经尝试过以下命令了。知道怎样才能找到Track按钮的id?

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

假设我们输入跟踪号“1ZW2E2360449018801”,点击该按钮后会打开一个新网页。我想点击“发货进度”栏并复制出现的表格。有什么建议吗?

2 个答案:

答案 0 :(得分:2)

这将完成它。

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

答案 1 :(得分:1)

这样的事情应该有效:

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

请注意它的getElement * s * ByName,因此它返回一个集合,而不是单个元素。

相关问题