html - 从下拉菜单中单击按钮 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
推荐阅读
- git - .gitignore 即使在使用“git rm -r --cached”后也不会跟踪我的文件。和“git add。”?
- python - 即使 sys.path 显示目录,模块导入错误?
- linux - 从 _start 以外的函数调用 dlsym 崩溃
- javascript - 在特定点停止固定元素滚动
- macos - 在 edgeSDK Oauth Tool 上找不到项目
- ios - 将 iOS CMDeviceMotion 传递给 THREE.js 以旋转球面全景
- regex - .htaccess 如何删除文件扩展名和索引文件
- gitlab-ci - 在从 ECR 提取图像之前如何登录 AWS?
- amazon-web-services - AWS S3 同步创建具有不同于存储桶的权限的对象
- python - (Django)当我尝试将夹具文件加载到我的数据库中时,我不断收到字段冲突错误