首页 > 解决方案 > 如何单击具有相似类名和属性的 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 元素下方。我不确定这是否有帮助,但如果需要,我绝对可以提供更多网页代码。

谢谢!

标签: vbainternet-explorer

解决方案


您可以使用 document.getElementsByClassName 方法或 document.getElementsByTagName 方法来获取按钮(它将返回一个数组),然后遍历该数组并根据innerText属性区分它们。更详细的,你可以查看这篇文章

此外,您还可以添加一些自定义属性并设置不同的值,然后使用它来区分它们。


推荐阅读