Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在selenium web驱动程序中使用父轴时出现问题::*轴_Java_Xpath_Selenium_Webdriver - Fatal编程技术网

Java 在selenium web驱动程序中使用父轴时出现问题::*轴

Java 在selenium web驱动程序中使用父轴时出现问题::*轴,java,xpath,selenium,webdriver,Java,Xpath,Selenium,Webdriver,我正在尝试使用通配符在selenium中向上导航DOM,使用类似这样的内容 ArrayList<WebElement> list = (ArrayList<WebElement>) driver.findElements(By.xpath("//div[contains(text(),'div_text')]/parent::*]")); 同意这不是最有效的方法,而是更复杂的xpath表达式,如 driver.findElements(By.xpath("//d

我正在尝试使用通配符在selenium中向上导航DOM,使用类似这样的内容

    ArrayList<WebElement> list = (ArrayList<WebElement>) driver.findElements(By.xpath("//div[contains(text(),'div_text')]/parent::*]"));
同意这不是最有效的方法,而是更复杂的xpath表达式,如

driver.findElements(By.xpath("//div[text()='title']/[name(parent::*) = 'table'"));
在web驱动程序中似乎不起作用


谢谢你对这一点的理解。

如果我正确理解了你的问题,你想要的是祖先而不是父母

祖先:选择当前节点父节点的所有祖先(父节点、祖辈节点等)
父节点:选择当前节点的父节点


请尝试
//div[text()='title']/祖先::table
对于表祖先

只有一个父元素。你可能在寻找祖先:


不起作用的查询有语法错误,您在不完整的axies步骤上应用了谓词(…
/[name(parent:*)
…,节点或a
*
丢失)。

太好了,非常感谢。我刚刚添加了我正在查找的表属性,它工作得非常好。//div[contains(text(),'fake')]/祖先::table[@class='today-group-header']会这么做,但还没有这个名声。尽管如此,我还是很感激。
driver.findElements(By.xpath("//div[text()='title']/[name(parent::*) = 'table'"));
//div[contains(text(),'div_text')]/ancestor::*