xpath - 使用具有强标记的唯一标识符的按钮的 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> <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']
任何帮助都将不胜感激。
解决方案
strong
node 不是后代,而是的兄弟,button
因此您可以使用下面的 XPath 来定位所需的按钮:
//button[@title='Add Option' and following-sibling::strong[normalize-space(text())='FN 3/087/062/2']]
推荐阅读
- google-kubernetes-engine - 如何为我的 gcloud vpn 授予对 gke 服务的访问权限
- python - 从某些 csv 文件列中写入 Pandas 系列
- php - 如何检查用户是否具有一对一关系的角色?
- arrays - 使用 for 循环从数组中添加整数
- amazon-web-services - SCP 阻止用户更改 s3:PutBucketPublicAccessBlock" 仅当当前已检查该设置时
- python - Matplot图表在熊猫数据帧的for循环中累积叠加
- javascript - GoogleSheets 脚本在表单提交时发送电子邮件,我应该如何处理空白单元格的格式错误?
- flutter - 带有粘性标题的 Gridview.builder
- css - 使用 SVG 文件,而不是 inline-svg,作为 CSS 掩码?
- blazor - 有没有办法在不覆盖现有类名的情况下将类名添加到 blazor 组件?