xpath multiple conditions
In selenium IDE, I need to find the 3rd link whose text is 'XXX'
<tr>
<td>clickAndWait</td>
<td>//a[text()='XXX'][3]</td>
<td></td>
</tr>
error: element not 开发者_开发百科found, any idea?
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. 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]
. Note that for the last example you would need to proceed the locator with xpath=
.
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. Obviously, there are no such nodes, and you do not want this but you want the 3-rd from all such a
elements.
This is exactly selected by the first XPath expression above.
精彩评论