【问题标题】:Xpath to select button from table cell depending on text contained within specific cellXpath 根据特定单元格中包含的文本从表格单元格中选择按钮
【发布时间】:2019-02-08 13:58:49
【问题描述】:

在我的网络应用程序中,我试图在表格的单元格中选择一个按钮。

并非每个单元格都包含显示详细信息按钮,并且该按钮仅根据该单元格中的文本显示

截图如下

<td>
    Allocated
    <button ng-show="row.entitlementId" id="btnShowDetails" class="btn btn-primary btn-sm" style="width: 110px; float:right;" ng-click="showAllocationMonetaryDetails(row.entitlementId, CisBusinessID);" title="Show Details">
         <span class="glyphicon glyphicon-search"></span>Show Details
    </button>
    <br>
    <div style="font-size: small; color: darkgreen" ng-show="row.manualEstablishCommandType >= 0">
         Adjustment
    </div>
    <div style="font-size: small; color: darkgreen" ng-show="row.manualReclaimCommandType >= 0">

    </div>
</td>

我尝试使用以下 xpath 来定位显示详细信息按钮,但它不起作用。

("//td[contains(.,'Allocated') and (contains(@id,'btnShowDetails'))]")

有人知道如何选择“显示详细信息”按钮吗?

谢谢

【问题讨论】:

标签: selenium xpath


【解决方案1】:

@id='btnShowDetails'不是td的属性,而是子button的属性

试试下面的 XPath 来选择需要的元素:

//td[starts-with(normalize-space(),'Allocated') and button[@id='btnShowDetails']]

//td[normalize-space(text())='Allocated' and button[@id='btnShowDetails']]

【讨论】:

  • 谢谢 :) 这使我能够选择包含按钮的单元格,但是每当我使用此 xpath 时,它都不会隔离并选择按钮
  • 如果要选择按钮://td[normalize-space(text())='Allocated']/button[@id='btnShowDetails']
【解决方案2】:

在您的单元格 td 中,按钮下方没有 id 属性,您可以像这样修改 xpath:

//td[contains(.,'Allocated') and (contains(button/@id,'btnShowDetails'))]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-10
    相关资源
    最近更新 更多