且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从 <Strong> 获取文本使用 xpath 标记?

更新时间:2021-12-11 22:39:36

可以使用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);