在VBA Selenium中如何定位并点击 and return values found on the next page to spreadsheet and loop through all results?

问题描述 投票:-1回答:1

我正在尝试单击页面上的元素,并返回页面上每个结果的下一页上找到的值。我想从下一页得到的结果是谁发货。

这是相关的VBA代码:

   Dim FOrderID As Object, FOrderList As Object, FOL As Long
    FOL = 1
    t = Timer
    Do
        Set FOrderList = driver.FindElementsByXPath("//div[3]//div[3]//span/a")
        If Timer - t > MAX_WAIT_SEC Then Exit Do
    Loop While FOrderList.Count = 0
    If FOrderList.Count > 0 Then

        For Each FOrderID In FOrderList
            FOL = FOL + 1
            ActiveSheet.Cells(FOL, 7) = FOrderID.Text

            .Click

            With .FindElementByXPath("//a[text()[contains(.,'Shipments')]]")
                .Click
            End With

            ActiveSheet.Cells(FOL, 8) = .FindElementById("sc14821").Text
        Next


    End If

这是指向主页上相关HTML的pastebin链接。 https://pastebin.com/epFSzG8E

也是我想从中获取信息的页面。 https://pastebin.com/xBQnbQza

请注意,在主页面上,标题元素也具有相同的类。

这里是我试图点击/使用的元素的Xpath:// [@ id =“sc25579”] / div / div / div / div / div [3] / div / div [1] / div / div [1] / DIV [3] / DIV [1] / DIV / DIV / DIV [2] / DIV / DIV [4] /跨度/一

excel vba selenium web-scraping selenium-chromedriver
1个回答
1
投票

从讨论:

您需要的当前页面

FOrderID.click

单击是对象的方法,因此您需要为其提供一个对象

下一页

.FindElementByCss(".status-history").text

因为id是动态的

© www.soinside.com 2019 - 2024. All rights reserved.