vba单击没有href链接的css按钮

时间:2017-04-15 08:21:10

标签: css vba

我试图单击css中的按钮但没有成功,代码在运行时不会出现任何错误,但它也没有单击。

我想点击的按钮在这里:

<form id="transactionHistoryReportForm" class="report-form">

  <div style="clear:both;" class="days-back-buttons">
    <a href="#" class="io-button editColumns">Edit Columns</a>
    <a class="io-button daysBackButton" data-days="1" href="#"><span>Last Day</span></a>
    <a class="io-button daysBackButton" data-days="7" href="#"><span>Last 7 Days</span></a>
    <a class="io-button daysBackButton active-days" data-days="30" href="#"><span>Last 30 Days</span></a>
    <a class="io-button daysBackButton" data-days="180" href="#"><span>Last 180 Days</span></a>
  </div>
  <!--
    <div class="currently-showing">
        <span>Currently showing:</span>
        <span data-id="currently-showing-value"></span>
    </div>
-->
  <input type="hidden" class="daysBack" name="daysBack" value="30">
  <input type="hidden" class="account" name="account" value="username">
  <input type="hidden" class="deviceId" name="deviceId" value="">
</form>

默认情况下选择最近30天。最后180天是要点击的按钮。我试图运行以下代码但没有成功:

Set oElementCollection = IE.document.getElementsByClassName("report-form")
For Each link In oElementCollection
If link.innerHTML = "Last 180 Days" Then
link.Click
Exit For
End If
Next link

然而,对于同一网站上的另一个链接,这是完美的。

1 个答案:

答案 0 :(得分:0)

解决方案就是这么简单

    Set backbutton = IE.document.getElementsByClassName("io-button daysBackButton").Item(Index:=3)
    backbutton.Click

按类名获取元素并指向第三项(First为0,因此为4-1)