如何使用xpath从<strong>标签获取文本?

时间:2017-11-21 11:32:20

标签: selenium-webdriver webdriver

这是我的HTML代码

SELECT p.codigo_cl client_code, p.n_ordem proposal_id, p.data proposal_data, p.baumuster proposal_baumuster, p.vendedor proposal_seller_code, p.modelo proposal_model, p.preco_base proposal_base_price, p.preco_ext proposal_extras, p.ia proposal_ia, p.desconto proposal_discount
FROM proposta.DBF p 
INNER JOIN cliente.dbf c ON c.processo = p.codigo_cl 
WHERE p.N_ORDEM = (SELECT MAX(N_ORDEM) FROM proposta.DBF)

2 个答案:

答案 0 :(得分:0)

Selenium具有从WebElements获取文本的功能,您不需要在xpath中提取文本。使用

driver.findElement(By.xpath("//strong")).getText();

答案 1 :(得分:0)

您可以使用Xpath来获取它,请找到以下代码:

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

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

你可以使用像

这样的另一个xpath
WebElement eleText=driver.findElement(By.xpath("//*[contains(text(),'Telephone:')]"));

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