Xpath:使用同级Xpath找到同级XPath

时间:2019-02-15 08:32:09

标签: java selenium-webdriver xpath

我在查找需要单击的输入(复选框)元素的xpath时遇到困难。我正在尝试使用另一个span元素来定位它。元素包含Angular属性,不知道这有关系吗?

元素的结构如下:

<div _ngcontent-c6="" class="py-1" style="">
  <input _ngcontent-c6="" type="checkbox">
  <span _ngcontent-c6="" class="pl-2">Company name</span>
</div>

我可以使用以下xpath找到span元素:

"//span[text() = '" + SearchInput + "']"

但是我很难点击以下输入元素。以下xpath对我不起作用:

"//span[text() = '" + SearchInput + "']/following-sibling::input"
"//span[text() = '" + SearchInput + "']/following-sibling::input[@type = 'checkbox']"

我已经四处寻找答案,但是似乎找不到适合我的答案。如果有人可以帮助或指出我真正适合我的问题,我们将不胜感激!

1 个答案:

答案 0 :(得分:1)

也许有更好的方法可以做到,但是以下对我有用。搜索一个孩子为import DemoButton from "./DemoButton"; export default class Heal extends Component { constructor(props) { super(props); this.state = { isbuttonpress: false }; } render() { return ( <View> <Header /> <DemoButton buttonTitle="0"/> <DemoButton buttonTitle="1"/> <DemoButton buttonTitle="2"/> <DemoButton buttonTitle="3"/> <DemoButton buttonTitle="4"/> <DemoButton buttonTitle="5"/> </View> ) } } 的{​​{1}},并获得该div的{​​{1}}孩子{p}

span
相关问题