VBA Selenium - return 具有特定属性的所有元素

VBA Selenium - return all elements with specific attribute

我在 Excel VBA 中使用 Selenium 来抓取一些网站。我希望在网页上找到类似于以下代码段的所有元素:

<div class="outcomeName_f18x6kvm" data-automation-id="racecard-outcome-name"><span class="size14_f7opyze Endeavour_fhudrb0 medium_f1wf24vo">1. The Running Man</span><span class="size11_fwt0xu4 Endeavour_fhudrb0 light_f2noysy">&nbsp;(5)</span></div>

特别是,我希望找到包含属性 data-automation-id 的所有元素,然后按具有 racecard-outcome-name 作为此属性的元素进行过滤,但是一旦我可以 racecard-outcome-name 这应该很容易 return 具有此属性的所有元素。

目前我正在使用类似于

的东西

table = bot.FindElementsBy.Attribute("data-automation-id") 但我知道这是对该运算符的错误使用。如果您能指出正确的方向,请告诉我。

感谢 QHarr 提供的有用评论。我最终实施了以下解决方案来查找 data-automation-id 被标记为 racecard-outcome-name 的元素:

    Set table = bot.FindElementsByCss("[data-automation-id]")
    
    Dim i As Integer, tableCount As Integer
    tableCount = table.count
    For i = 1 To table.count
        If table(i).Attribute("data-automation-id") = "racecard-outcome-name" Then
            MsgBox table(i).Text
        End If
    Next i