html - 基于文本的跨度的 XPath?

标签 html xml xpath selenium-webdriver

我无法使用我尝试过的 XPath 找到第一个跨度:

//*[@id='student-grid']/div[2]/div[1]/table/tbody/tr[1]/td/span/span[contains(text(), 'Edit School')]

选择带文本的范围 - 编辑学生按钮

<tbody role="rowgroup">
<tr class="" data-uid="2f3646c6-213a-4e91-99f9-0fbaa5f7755d" role="row" aria-selected="false">
<td class="select-row" role="gridcell">
<td class="font-md" role="gridcell">marker, Lion</td>
<td role="gridcell">TESTLINK_1_ArchScenario</td>
<td role="gridcell">1st</td>
<td role="gridcell">Not Started</td>
<td role="gridcell"/>
<td role="gridcell"/>
<td role="gridcell">QA Automation TestLink Folders</td>
<td class="k-cell-action" role="gridcell"/>
<td class="k-cell-action detail-view-link font-md" role="gridcell">
<span class="button-grid-action kendo-lexia-tooltip icon-pencil" role="button" title="Edit Student">
<span>Edit Student</span>
</span>
</td>
<td class="k-cell-action archive-link font-md" role="gridcell">
<span class="button-grid-action kendo-lexia-tooltip icon-archive" role="button" title="Archive Student">
<span>Archive Student</span>
</span>
</td>
</tr>
</tbody>

最佳答案

如果你想select span with text - Edit Studen试试这个:

//span[@title='Edit Student']/span
//span[text()='Edit Student']

如果你想选择 Edit Studen with role="button" 试试这个:

//span[@title='Edit Student'][@role='button']
//span[@role='button'][./span[text()='Edit Student']]
//span[@role='button'][./span[.='Edit Student']]

关于html - 基于文本的跨度的 XPath?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46449200/

相关文章:

android - 我找不到安卓主页图标

XML 签名 - 签署 KeyInfo 元素的原因

java - 创建自定义 XPath 函数来修改 Java 中的节点集

javascript - 使用其他页面中的 'href' 到达(即取消隐藏)特定 div

html - 在 Bootstrap 的行列中创建垂直居中的 img

c# - XDocument 错误名称不能以 '<' 字符开头,十六进制值 0x3C

xml - 选择所有具有偶数ID的元素

java - 使用 Selenium Webdriver 查找并切换到正确的框架

html - 语义 UI 将字段 div 中字段的宽度加倍

javascript - 如何用 twemoji 替换 html 中的表情符号?