如何使用selenium查找标记外部的文本?
我想从下面的代码中检索所有标记为“Working”的锚标记如何使用selenium查找标记外部的文本?,selenium,xpath,tags,Selenium,Xpath,Tags,我想从下面的代码中检索所有标记为“Working”的锚标记 <div class="A"> <a href="facebook.com">Profile 1</a> Working <br/> <a href="gmail.com">Profile 2</a> <br/> <a href="l
<div class="A">
<a href="facebook.com">Profile 1</a>
Working
<br/>
<a href="gmail.com">Profile 2</a>
<br/>
<a href="linkedin.com">Profile 3</a>
Working
<br/>
</div>
任何人都可以提供xpath来实现这一点。请尝试以下表达式:
//div[@class='A']/text()[normalize-space()="Working"]/preceding-sibling::a[1]
返回
<a href="facebook.com">Profile 1</a>
<a href="linkedin.com">Profile 3</a>
如果您想将文本节点作为输出,它将不起作用,但此表达式返回WebElement
,因此它是okHey Kudos Andersson…它工作正常。。我从未遇到过这个“normalize-space()”。我从哪里可以学到这些?。请向我推荐更多关于这些XPath类型的技术。您有任何参考资料吗?@raakigade,您可以检查以了解如何创建好的XPath
表达式,您可以在函数列表中找到XPath
函数
<a href="facebook.com">Profile 1</a>
<a href="linkedin.com">Profile 3</a>