テキストが含まれているすべてのノードを選択したいと思います。
この例では、外側のshouldBeIgnored
タグを選択しないでください。
<shouldBeIgnored>
<span>
the outer Span should be selected
</span>
</shouldBeIgnored>
他のいくつかの投稿は、次のようなことを示唆しています//*/text()
。
ただし、これはFirefoxでは機能しません。
これは、問題を再現するための小さな単体テストです。
public class XpathTest {
final WebDriver webDriver = new FirefoxDriver();
@Test
public void shouldNotSelectIgnoredTag() {
this.webDriver.get("http://www.s2server.de/stackoverflow/11773593.html");
System.out.println(this.webDriver.getPageSource());
final List<WebElement> elements = this.webDriver.findElements(By.xpath("//*/text()"));
for (final WebElement webElement : elements) {
assertEquals("span", webElement.getTagName());
}
}
@After
public void tearDown() {
this.webDriver.quit();
}
}