我正在编写一个方法来通过 XPath 查找任何给定元素的父元素。我真的很困惑为什么这不起作用。
protected WebElement findParent(WebDriver driver, WebElement element) {
return driver.findElement(By.xpath("parent::*"));
}
最佳答案
使用..
xpath表达式:
return element.findElement(By.xpath(".."));
关于selenium - 通过 XPath 相对查找元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25125308/