单击下拉菜单VBA中的按钮



我在单击下拉菜单中的按钮时遇到问题。这是 HTML:

<div class="dropdown text-center">
<button class="btn btn-secondary dropdown-toggle" aria-expanded="false" aria-haspopup="true" type="button" data-toggle="dropdown">
<!-- react-text: 400 -->Process Path Group: <!-- /react-text --><!-- react-text: 401 -->ALL<!-- /react-text -->
</button>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="statusProcessPathGroupDropdown" style="left: 0px; top: 0px; position: absolute; transform: translate3d(206px, 37px, 0px);" x-placement="bottom-end"><button class="dropdown-item active" type="button">ALL</button><button class="dropdown-item" type="button">SINGLE</button><button class="dropdown-item" type="button">MULTI</button></div>
</div>

我想单击"全部"按钮,但我无法到达那里单击它。我什么都试过了。这是我最后一次尝试。

Sub Macro()
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = True
Set IE = New InternetExplorerMedium
url1 = "url1"
With IE
.Visible = True
.navigate url1

End With
Set AvailableLinks = IE.document.getElementByTagName("button")
For Each cLink In AvailableLinks
If cLink.innerHTML = "ALL" Then
cLink.Click
End If

感谢您的帮助。

没有.getElementByTagName()这样的东西。

您要查找的方法为.getElementsByTagName(),它返回 html 元素的集合。

同样在您的情况下,按钮元素的内部 html 是:

<!-- react-text: 400 -->Process Path Group: <!-- /react-text --><!-- react-text: 401 -->ALL<!-- /react-text -->

而不仅仅是ALL

所以,你可以选择这样的东西:

Set AvailableLinks = IE.document.getElementsByTagName("button")
For Each clink In AvailableLinks
If clink.innerHTML = "<!-- react-text: 400 -->Process Path Group: <!-- /react-text --><!-- react-text: 401 -->ALL<!-- /react-text -->" Then
clink.Click
End If
Next clink

甚至更简单:

Set AvailableLinks = IE.document.getElementsByTagName("button")
For Each clink In AvailableLinks
If clink.innerText = "Process Path Group: ALL" Then
clink.Click
End If
Next clink

最新更新