Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用selenium查找标记外部的文本?_Selenium_Xpath_Tags - Fatal编程技术网

如何使用selenium查找标记外部的文本?

如何使用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

我想从下面的代码中检索所有标记为“Working”的锚标记

    <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>