【问题标题】:Unable to identify an element using preceeding-sibling无法使用前置兄弟识别元素
【发布时间】:2020-09-06 00:00:20
【问题描述】:

该网站 - https://www.jqueryscript.net/demo/Drop-Down-Combo-Tree/ 显示“多选”选项供用户选择不同的选项。

我已经确定了选择“Choice 6 2 3”的 xpath,即 (//span[text()='choice 6 2 3'])[1]

此外,我还确定了该元素的父元素,即 (//span[text()='choice 6 2 3'])[1]//parent::li[@class='ComboTreeItemChlid' ]

从这里,如何使用前兄弟概念选择“选择 6 2 2”?

我尝试使用 (//span[text()='choice 6 2 3'])[1]//parent::li[@class='ComboTreeItemChlid']//preceeding-sibling::li 但显示什么都没有。

【问题讨论】:

  • 能不能把你正在使用的代码加进去。

标签: selenium selenium-webdriver


【解决方案1】:

对于您的元素,只有一个父 li 并且哪个类不是 ComboTreeItemChlid,事实上我在页面中找不到该类的任何 li。无论如何,当您使用父节点时,无需提及任何属性,并且在带有 preceding-sibling 的 xpath 下方将选择选项 Choice 6 2 2

//span[text()='choice 6 2 3']//parent::li//preceding-sibling::li[1]

选择选项Choice 6 2 1

//span[text()='choice 6 2 3']//parent::li//preceding-sibling::li[1]

【讨论】:

    猜你喜欢
    • 2021-09-24
    • 1970-01-01
    • 2019-05-06
    • 2019-09-15
    • 2016-03-28
    • 1970-01-01
    • 2010-12-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多