在selenium IDE中,我需要点击包含文本“XXX”的第n个链接。怎么办呢?
< TR>
< TD> clickAndWait< / TD>
< TD> //一个[文本()= 'XXX'] [$ {链接}]< / TD>
< TD>< / TD>
< / TR>
上面的代码说[错误]元素// a [text()='XXX'] [9]即使它有效也找不到,
答案 0 :(得分:2)
对于非结构化链接,您可以尝试//body/descendant::a[text()='a link'][9]
之类的内容。后代轴将展平所有后代'a'标记,因此position()将采用它们在文档中出现的顺序,而不是基于每个标记的先前兄弟。
如果链接是半结构化的,如下所示,那么
//div[@id='fu']//a[text()='a link']/../following-sibling::*//a[text()='a link']/../following-sibling::*//a[text()='a link']/../following-sibling::*//a[text()='a link']/../following-sibling::*//a[text()='a link']/../following-sibling::*//a[text()='a link']/../following-sibling::*//a[text()='a link']/../following-sibling::*//a[text()='a link']/../following-sibling::*//a[text()='a link']
可以找到具有给定结构的第9个匹配链接。
<p>a segment, outside the containing div, with <a href="www.google.com">a link</a>.</p>
<div id="fu">
<p>some text <a href="www.google.com">a link</a>.</p>
<p>some text <a href="www.google.com">a link</a>.</p>
<p>some text <a href="www.google.com">a different link</a>.</p>
<p>some text <a href="www.google.com">a link</a>.</p>
<p>some text <a href="www.google.com">a link</a>.</p>
<p>some text <a href="www.google.com">a link</a>.</p>
<p>some text <a href="www.google.com">a link</a>.</p>
<p>some text <a href="www.google.com">a link</a>.</p>
<p>some text <a href="www.google.com">a link</a>.</p>
<p>some text <a href="www.google.com">a link</a>.</p>
<p>some text <a href="www.google.com">a link</a>.</p>
<p>some text <a href="www.google.com">a link</a>.</p>
<p>some text <a href="www.google.com">a link</a>.</p>
<div></div></div>