2017-10-20 528 views
-1

我有几个看起来完全相同的对象,除了'span class'内的文本。在下面的例子中,我需要找到的电话号码,“15551234567”:Selenium XPath:如何在span类标签中查找文本?

<span class="contact-number">+15551234567 </span> 

我尝试了好几种CSS选择器和XPath查询,并没有多少运气。

任何帮助将不胜感激!此

+1

显示其他类似元素或更好的部分与父项目的HTML,所以我们会尝试正确识别所需的项目 –

回答

0

CSS seletor:

span.contact-number 

的XPath:

//span[@class='contact-number'] 

//span[text()='+15551234567 '] 

,你可以以这种方式得到定位文本:

webdriver.findElement(By.xpath("locatorHere")).getText(); 
+0

谢谢!这里是我最终使用的:driver.findElement(By.xpath(“// span [text()='+ 15551234567']”))。click(); – Bullfrog

+0

好工作)你欢迎 –

相关问题