如何从 <Strong> 获取文本使用 xpath 标记? [英] How to get text from <Strong> tag using xpath?

查看:40
本文介绍了如何从 <Strong> 获取文本使用 xpath 标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的 HTML 代码

Here is my HTML code

<p>
<strong>Telephone:</strong>
 1(111)656-3485
<br/>

推荐答案

可以使用Xpaths获取,代码如下:

You can use Xpaths to get it, Please find the code below:

WebElement eleText=driver.findElement(By.xpath("//strong[contains(text(),'Telephone:')]"));

String textTelephone=eleText.getText();
System.out.println(textTelephone);

您可以使用另一个类似的 xpath

You can use another xpath like that

WebElement eleText=driver.findElement(By.xpath("//*[contains(text(),'Telephone:')]"));

String textTelephone=eleText.getText();
System.out.println(textTelephone);

这篇关于如何从 &lt;Strong&gt; 获取文本使用 xpath 标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆