d0x*_*d0x 2 firefox selenium xpath webdriver
我想选择所有节点,其中包含文本.
在此示例中shouldBeIgnored,不应选择外部标记:
<shouldBeIgnored>
<span>
the outer Span should be selected
</span>
</shouldBeIgnored>
Run Code Online (Sandbox Code Playgroud)
其他一些帖子提示如下://*/text().
但是,这在firefox中不起作用.
这是一个重现问题的小型UnitTest:
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();
}
}
Run Code Online (Sandbox Code Playgroud)
如果要选择包含文本的所有节点,则可以使用
//*[text()]
Run Code Online (Sandbox Code Playgroud)
在xpath之上将查找包含文本的任何元素.注意text()用于确定当前节点是否有文本的函数.
在您的情况下,它将选择<span>标记,因为它包含文本.
| 归档时间: |
|
| 查看次数: |
10620 次 |
| 最近记录: |