首页 > 解决方案 > 面临创建 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,这将有助于完整。

注意:列和下拉是连接的,如果列位置被挂起,那么下拉位置也会相对于列发生变化

谢谢,

标签: javaseleniumselenium-webdriver

解决方案


您可以使用span columnif the textis的引用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()]

推荐阅读