vba - 如何单击具有相似类名和属性的 IE 按钮
问题描述
我目前正试图点击私人网站上的按钮。我尝试单击的按钮具有相同的属性,我无法区分我需要单击哪个按钮。这是我试图点击的三个按钮。如您所见,它们是相似的,除了按钮上的文本。如何选择特定按钮并单击它?
<button ng-repeat="punch in $ctrl.nextPunches" ng-disabled="punch.sendingPunch || $ctrl.sendingPunch" type="button" class="btn btn-default ng-binding ng-scope" ng-click="$ctrl.addPunch(punch)" style="">
<!-- ngIf: punch.sendingPunch -->
Check In
</button>
==================================================== ==========================
<button ng-repeat="punch in $ctrl.nextPunches" ng-disabled="punch.sendingPunch || $ctrl.sendingPunch" type="button" class="btn btn-default ng-binding ng-scope" ng-click="$ctrl.addPunch(punch)">
<!-- ngIf: punch.sendingPunch -->
Start Meal
</button>
==================================================== =========================
<button ng-repeat="punch in $ctrl.nextPunches" ng-disabled="punch.sendingPunch || $ctrl.sendingPunch" type="button" class="btn btn-default ng-binding ng-scope" ng-click="$ctrl.addPunch(punch)">
<!-- ngIf: punch.sendingPunch -->
Check Out
</button>
我试过用这个:
Set HTMLButtons = HTMLDoc.getElementsByTagName("button")
For Each HTMLbutton In HTMLButtons
Debug.Print HTMLbutton.getAttribute("ng-click"), HTMLbutton.getAttribute("type"), HTMLbutton.getAttribute("ng-repeat"), HTMLbutton.getAttribute("ng-disabled")
Next HTMLbutton
HTMLButtons(2).Click
但是,显示在即时窗口上的按钮没有帮助,并且当我使用 .Click 命令时它不会单击任何按钮。这些按钮位于网页上的 UI 元素下方。我不确定这是否有帮助,但如果需要,我绝对可以提供更多网页代码。
谢谢!
解决方案
您可以使用 document.getElementsByClassName 方法或 document.getElementsByTagName 方法来获取按钮(它将返回一个数组),然后遍历该数组并根据innerText属性区分它们。更详细的,你可以查看这篇文章。
此外,您还可以添加一些自定义属性并设置不同的值,然后使用它来区分它们。
推荐阅读
- html - 如何删除表格中行之间的空格?
- regex - 匹配以但不包括开头的字符串的正则表达式
- html - Bootstrap 居中 div 图像和文本
- docker - ./psh.phar docker:ssh 没有执行
- android - 如何在调用 Google Billing 功能之前检查用户是否在设备上登录了 Google Play 帐户
- spring - Spring Boot @Async 方法*有时*未调用
- node.js - MERN 将照片上传到 Cloudinary 然后更新用户
- c++ - 使用继承时模板中的函数解析错误
- python - 为什么在处理纯文本文件时会发生单字节损坏?
- java - 使用 JAXB 解组特定节点