Xpath用于在还返回多个隐藏按钮时选择显示的按钮

时间:2018-07-24 11:16:14

标签: xpath

我正在尝试在Web应用程序上选择以下“撤消”按钮

enter image description here

撤消按钮的HTML由以下内容组成

<a href="" style="vertical-align: middle" class="btn btn-primary btn-sm" ng-show="true" ng-click="executeUndoCommand(transfer)">Undo</a>

表格中包含“撤消”按钮的行由以下内容组成

<tr ng-repeat="transfer in completedTransfersSummary track by $id(transfer)">
                    <td style="vertical-align: middle" ng- 
style="transfer.isDisabled &amp;&amp; {color:'#A6A6A6'}" ng-class=" 
{'highlight' : transfer.transferorBusinessId == CisBusinessID }" 
class="highlight">608445</td>
                    <td style="vertical-align: middle" ng- 
style="transfer.isDisabled &amp;&amp; {color:'#A6A6A6'}" ng-class=" 
{'highlight' : transfer.transfereeBusinessId == CisBusinessID }">608446</td>
                    <td style="vertical-align: middle" nowrap="" ng- 
style="transfer.isDisabled &amp;&amp; {color:'#A6A6A6'}">Merger</td>
                    <td style="vertical-align: middle" nowrap="" ng- 
 style="transfer.isDisabled &amp;&amp; {color:'#A6A6A6'}">19/07/2018</td>
                    <td style="vertical-align: middle" nowrap="" ng- 
 style="transfer.isDisabled &amp;&amp; {color:'#A6A6A6'}">02/01/2018</td>
                    <td style="vertical-align: middle" nowrap="" ng- 
 style="transfer.isDisabled &amp;&amp; {color:'#A6A6A6'}">1.00 entitlements @ 
€229.27</td>
                    <td style="vertical-align: middle" ng- 
style="transfer.isDisabled &amp;&amp; {color:'#A6A6A6'}">526461</td>
                    <td style="vertical-align: middle" ng- 
 style="transfer.isDisabled &amp;&amp; {color:'#A6A6A6'}">2018</td>
                    <td style="vertical-align: middle" ng- 
 style="transfer.isDisabled &amp;&amp; {color:'#A6A6A6'}"></td>
                    <td style="vertical-align: middle;" ng- 
 show="undoWithdrawRoleAssignedToUser">
                        <div ng-show="transfer.transferorBusinessId == 
CisBusinessID">
                            <a href="" style="vertical-align: middle" 
class="btn btn-primary btn-sm" ng-show="true" ng- 
click="executeUndoCommand(transfer)">Undo</a>
                            <a href="" style="vertical-align: middle" 
class="btn btn-primary btn-sm ng-hide" ng-show="false" ng- 
click="showUndoModal(transfer)">Undo</a>

                            <a href="" style="vertical-align: middle" 
class="btn btn-default btn-sm" ng-show="true" ng- 
click="executeWithdrawCommand(transfer)">Withdraw</a>
                            <a href="" style="vertical-align: middle" 
class="btn btn-default btn-sm ng-hide" ng-show="false" ng- 
click="showWithdrawModal(transfer)">Withdraw</a>

                            <label style="vertical-align: middle" ng- 
show="false" ng-style="transfer.isDisabled &amp;&amp; {color:'#A6A6A6'}" 
class="ng-hide"></label>
                            <label style="vertical-align: middle" ng- 
show="false" ng-style="transfer.isDisabled &amp;&amp; {color:'#A6A6A6'}" 
class="ng-hide"></label>
                        </div>
                    </td>
                </tr>

我使用以下XPath突出显示了屏幕上的“撤消”按钮

("//tr[td='Merger']//a[@ng-click='executeUndoCommand(transfer)']")

它会返回我需要的按钮,但还会返回3个隐藏的按钮,对于正在运行的测试,我只需要选择显示的按钮即可。我需要的按钮是下面列表中的第4个

 $x("//tr[td='Merger']//a[@ng-click='executeUndoCommand(transfer)']")
(4) [a.btn.btn-primary.btn-sm.ng-hide, a.btn.btn-primary.btn-sm.ng-hide, 
a.btn.btn-primary.btn-sm.ng-hide, a.btn.btn-primary.btn-sm]
0
:
a.btn.btn-primary.btn-sm.ng-hide
1
:
a.btn.btn-primary.btn-sm.ng-hide
2
:
a.btn.btn-primary.btn-sm.ng-hide
3
:
a.btn.btn-primary.btn-sm
length
:
4

我将xpath更改为以下内容,以尝试选择显示的按钮,但这些按钮不起作用

$x("//tr[td='Merger']//a[@ng-click='executeUndoCommand(transfer)' and 
@class='btn btn-default btn-sm']")

$x("//tr[td='Merger']//a[@ng-click='executeUndoCommand(transfer)']//a[@ng- 
show='true']")

有人可以提出一种突出显示我需要的按钮的方法吗?

3 个答案:

答案 0 :(得分:1)

尝试类似的操作

//a[text()='Undo' and not(contains(@class,'hide'))]

答案 1 :(得分:0)

我相信这对您有用// tr [td ='Merger'] // a [@ ng-click ='executeUndoCommand(transfer)'] [@ class ='btn btn-default btn-sm']

答案 2 :(得分:0)

由于A链接按钮包含ng-show =“ true”或ng-show =“ false”的属性,因此该XPATH选择器应该起作用:

// a [text()='Undo'and @ ng-show =“ true”]