首页 > 解决方案 > 使用具有强标记的唯一标识符的按钮的 XPath

问题描述

我正在尝试找到一个强大的 xpath 来单击下面屏幕截图中的按钮

我要点击的按钮是蓝色的 +

在此处输入图像描述

元素的 HTML 由以下内容组成

  <td class="text-left">
                                                <button ng- 
   hide="!efsEditRole_RoleAssignedToUser" ng-disabled="!appSummaryVm.OR_fieldOptionsArray.length" id="btnAddFieldOption_2_OR" class="btn btn-primary btn-sm" ng-click="appSummaryVm.addOption($index, 'OR'); appSummaryVm.addOptionsByField(OR_field.fieldId, 'OR');" title="Add Option" aria-hidden="false">
                                                    <span class="glyphicon glyphicon-plus"></span>
                                                </button>
                                                <strong>FN 3/087/062/2</strong><br><strong>MEA 1.53ha</strong>&nbsp;<strong>
                                                    Tranche 2
                                                    <a href="" data-toggle="tooltip" title="The FCAT tranche year displayed is the FCAT currently applied to the field. FCAT determines the EFS field category and the eligibility of EFS(W) Options.  FCAT Tranche 1 = 2017. FCAT Tranche 2 = 2018. FCAT Tranche 3 = 2019.">
                                                        <span class="glyphicon glyphicon-info-sign"></span>
                                                    </a>
                                                </strong>
                                            </td>

我试图使用以下 xpath 找到按钮,但它不起作用。我需要能够选择特定 FN 唯一标识符的按钮。

//button[@title='Add Option']//strong[normalize-space(text())='FN 3/087/062/2']

任何帮助都将不胜感激。

标签: xpath

解决方案


strongnode 不是后代,而是的兄弟button因此您可以使用下面的 XPath 来定位所需的按钮:

//button[@title='Add Option' and following-sibling::strong[normalize-space(text())='FN 3/087/062/2']]

推荐阅读