如何为孙子兄弟姐妹编写xpath
How to write xpath for grand child siblings
enter image description here在一个页面上我有一行,我想根据行数据删除该行,即如果我有多行,我可以根据行(单元格)数据删除该行
我可以读取数据,也可以单独识别删除按钮。
但挑战在于,如果我有不止一行,那么我会得到超过 1 个匹配的删除按钮。
所以我想根据单元格数据删除行。
当我尝试使用父<<>>子节点逻辑时,我无法根据行数据找到删除按钮。
下面是我试过的 xpath,有人可以建议我如何正确 xpath
。
xpath
查找行数据:
//div[@class='ui-grid-draggable-row ng-scope ng-isolate-scope']/div/div[contains(@title,'ART_Location')]
xpath
找到删除按钮:
//div[@class='ui-grid-draggable-row ng-scope ng-isolate-scope']/div/div/button[@class='delete-data-collectors-monitor']
如果我合并两个 xpath(行数据与删除)
xpath= //div[@class='ui-grid-draggable-row ng-scope ng-isolate-scope']/div/div[contains(@title,'ART_Location')]/../button[@class='delete-data-collectors-monitor']
这里我没有识别出删除按钮,请建议。
尝试使用下面的 xpath
。
.//div[text()='ART_Location']/../..//button[@class='<class name of the button>']
如果您的删除按钮在最后一列,则使用下面的 xpath
:
.//div[text()='ART_Location']/../div[last()]/div/button[@class='<class name of the button>']
如果您的删除按钮出现在特定位置,请使用下面的 xpath
:
.//div[text()='ART_Location']/../following-sibling::div[position()=<position number from the ART_Location div>]/div/button
希望对您有所帮助。
enter image description here在一个页面上我有一行,我想根据行数据删除该行,即如果我有多行,我可以根据行(单元格)数据删除该行
我可以读取数据,也可以单独识别删除按钮。
但挑战在于,如果我有不止一行,那么我会得到超过 1 个匹配的删除按钮。
所以我想根据单元格数据删除行。
当我尝试使用父<<>>子节点逻辑时,我无法根据行数据找到删除按钮。
下面是我试过的 xpath,有人可以建议我如何正确 xpath
。
xpath
查找行数据:
//div[@class='ui-grid-draggable-row ng-scope ng-isolate-scope']/div/div[contains(@title,'ART_Location')]
xpath
找到删除按钮:
//div[@class='ui-grid-draggable-row ng-scope ng-isolate-scope']/div/div/button[@class='delete-data-collectors-monitor']
如果我合并两个 xpath(行数据与删除)
xpath= //div[@class='ui-grid-draggable-row ng-scope ng-isolate-scope']/div/div[contains(@title,'ART_Location')]/../button[@class='delete-data-collectors-monitor']
这里我没有识别出删除按钮,请建议。
尝试使用下面的 xpath
。
.//div[text()='ART_Location']/../..//button[@class='<class name of the button>']
如果您的删除按钮在最后一列,则使用下面的 xpath
:
.//div[text()='ART_Location']/../div[last()]/div/button[@class='<class name of the button>']
如果您的删除按钮出现在特定位置,请使用下面的 xpath
:
.//div[text()='ART_Location']/../following-sibling::div[position()=<position number from the ART_Location div>]/div/button
希望对您有所帮助。