java - 面临创建 x-path 的困难
问题描述
我正在使用 JAVA Selenium-3 面临的问题来创建 x-path,DOM 结构如下,
在这个 DOM
<span class="ant-table-column-title" xpath="1">Inspection_Status</span>
是一个列名。
和
<svg fill="currentColor" preserveAspectRatio="xMidYMid meet" height="1em" width="1em" viewBox="0 0 40 40" type="filter" class="ant-table-filter-icon custom-table-filter-icon ant-dropdown-trigger" title="Filter menu" style="vertical-align: middle; color: rgb(255, 255, 255);" xpath="3">
是一个下拉我要点击的下拉。
我创建了 xpath:
1. //th[6]//*[@title='Filter menu']
2. //th[6]//*[local-name()='svg']
但我不想在 x-path 中包含标签“th”,因为有多个“th”标签并且列位置正在改变。如果我得到包含列名的 xpath,这将有助于完整。
注意:列和下拉是连接的,如果列位置被挂起,那么下拉位置也会相对于列发生变化
谢谢,
解决方案
您可以使用span column
if the text
is的引用unique
。
//span[@class='ant-table-column-title' and text()='Inspection_Status']/ancestor::th[1]//*[local-name()='svg']
更新:尝试使用 [last()]
(//span[@class='ant-table-column-title' and text()='Inspection_Status']/ancestor::th[1]//*[local-name()='svg'])[last()]
推荐阅读
- vba - VB.net自动完成字符串选择后如何使DataGridView移动到下一个单元格而不是下一行?
- linux-kernel - 在 Linux 中通过交换机配置 I2C 总线
- graphql - GraphType 使用 ListGraphType 或使用 Connection 的第一个架构端点
- android - 在 EditText 中获取结果
- php - 将数据导出到excel文件
- navigation - 在squarespace 7.1中浏览不同页面时锚链接不起作用
- jquery - 在下面的 jQuery 代码中,我如何从 multiSelect 中进行选择
- javascript - react-router BrowserRouter与打字稿反应的问题?
- data-structures - 在加权图中找到最近的特殊节点
- scala - 如何在ScalaCheck中生成递增序列?