Xpath定位器到chekboks

时间:2019-03-19 11:02:31

标签: selenium xpath

如何使用文本“第1步:设置自我发展的方向”作为起点来选择要选择的Xpath定位器?

enter image description here

为方便起见,您可以从此处复制文本:

pdp-action-item-header__checkbox pdp-action-item-header__checkbox--unchecked

Step 1. Set the direction for self-development

我这样做了:

//div[@class='pdp-action-item-header__checkbox pdp-action-item-header__checkbox--unchecked']/descendant-or-self::div[text()='Step 1. Set the direction for self-development']

但这不对

3 个答案:

答案 0 :(得分:0)

您是否尝试过该xpath。

//div[text()(contains(.,'Step 1'))]/parent::/div[@class='pdp-action-item-header__checkbox pdp-action-item-header__checkbox--unchecked']

答案 1 :(得分:0)

可以使用xpath和多种功能。

"//div[contains(text(), 'Step 1. Set the direction for self-development')]/ancestor::div[contains(@class, 'pdp-action-item--goal')]//div[contains(@class, 'pdp-action-item-header__checkbox')]"

让我们分解一下

  1. 我们从所需的文本开始。
//div[contains(text(), 'Step 1. Set the direction for self-development')]
  1. 我们正在寻找其父元素。文本元素和复选框元素的共同父对象。 (确保我编写了正确的选择器)
/ancestor::div[contains(@class, 'pdp-action-item--goal')]
  1. 然后我们在通用父元素的上下文中查找复选框
//div[contains(@class, 'pdp-action-item-header__checkbox')]

答案 2 :(得分:0)

尝试使用此 xpath:

 //div[text()='Step 1. Set the direction for self-development']/preceding::div[@class='pdp-action-item-header__checkbox pdp-action-item-header__checkbox--unchecked']
相关问题