我有以下HTML代碼的HTML文件:的XPath建議根據需要來選擇文本
<!DOCTYPE html>
<html>
<head>
<title>page XYZ</title>
</head>
<body>
<p><b>bold text</b> some more text </p>
<p><b>1.</b> hello<br><b>2.</b> how<br><b>3.</b> do you do?</p><p>some more text in a paragraph.</p>
</body>
</html>
我需要寫的XPath與他們的文本,即打印3分,
1. hello
2. how
3. do you do?
到目前爲止我試過這個:(但它不是打印文字)
List<WebElement> list = driver.findElements(By.xpath("//p/following-sibling::p/b"));
for (int i = 0; i < list.size(); i++) {
WebElement el = list.get(i);
String text = el.getText();
System.out.println(text);
}
請給我建議。
// P [2]的工作(所以我接受你的答案),但同樣的硒,使用文本()的XPath函數表達式會將錯誤作爲無效選擇器引發。 – dheer