我需要从html中提取一个数字(代码)。我有下一个提取HTML中所有字符串的字符串:
String value = driver.findElement(By.xpath("//*[@id=\"htmlSourceContent\"]")).getText();
我只想提取代码(数字)
这是html:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
/* Email styles need to be inline */
</style>
</head>
<body>
<h1>Security Code</h1>
<p>
Please enter the code <b>394013</b>.
</p>
</body>
</html>
该代码是随机的<b>394013</b>.
答案 0 :(得分:0)
答案 1 :(得分:0)
下一个正确的解决方案:
WebElement myElement = new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.id("htmlSourceContent")));
String myText = ((JavascriptExecutor)driver).executeScript("return arguments[0].childNodes[23].textContent;", myElement).toString();