简体   繁体   English

xpath多个条件

[英]xpath multiple conditions

In selenium IDE, I need to find the 3rd link whose text is 'XXX' 在Selenium IDE中,我需要找到文本为“ XXX”的第三个链接

<tr>
  <td>clickAndWait</td>
  <td>//a[text()='XXX'][3]</td>
  <td></td>
</tr>

error: element not found, any idea? 错误:找不到元素,知道吗?

Use : 用途

(//a[text()='XXX'])[3]

The expression: 表达方式:

//a[text()='XXX'][3]

selects every a element that has some text child with value 'XXX' and which is the 3rd child of its parent. 选择每a有一些文字的孩子与价值元素'XXX' ,并且是其母公司的第三个孩子。 Obviously, there are no such nodes, and you do not want this but you want the 3-rd from all such a elements. 显然,有没有这样的节点,你不想这样,但是你想从所有这些的3挡a元素。

This is exactly selected by the first XPath expression above . 这是由上面的第一个XPath表达式精确选择的

As answered in my comment on selenium scripts 正如我对硒脚本的评论所回答

It may be because of a subtlety in XPath where //a[1] will select all descendant a elements that are the first para children of their parents, and not the first a element in the entire document. 可能是由于XPath的微妙之处, //a[1]将选择所有后代的元素是其父元素的第一个para子元素,而不是整个文档中的第一个元素。 It might work better for you to use something like //body/descendant::a[1] or anchor it to an element with an id like id('myLinks')/descendant::a[1] . 使用//body/descendant::a[1]或将其锚定到id为id('myLinks')/descendant::a[1]的元素可能会更好。 Note that for the last example you would need to proceed the locator with xpath= . 请注意,对于最后一个示例,您将需要使用xpath=进行定位。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM