Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/391.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 前一个兄弟姐妹不工作_Java_Selenium_Selenium Webdriver_Xpath - Fatal编程技术网

Java 前一个兄弟姐妹不工作

Java 前一个兄弟姐妹不工作,java,selenium,selenium-webdriver,xpath,Java,Selenium,Selenium Webdriver,Xpath,请尝试使用下面的xpath,它会起作用 // Option 1 String xpath = "//div[div/span[@role='columnheader' and text()='Product']" + "//span[contains(@class, 'ag-icon-menu')]" driver.findElement(By.xpath(xpath)).click(); // Option 2 String xpath = "//div[div/span[@role=

请尝试使用下面的xpath,它会起作用

// Option 1
String xpath = "//div[div/span[@role='columnheader' and text()='Product']" + 
"//span[contains(@class, 'ag-icon-menu')]"

driver.findElement(By.xpath(xpath)).click();


// Option 2
String xpath = "//div[div/span[@role='columnheader' and text()='Product']"
driver.findElement(By.xpath(xpath))
      .findElement(By.cssSelector("span.ag-icon-menu"))
      .click()

当class属性有多个唯一值时,我们可以使用“AND”条件

选择第一个类是
ag-header-icon
,而不是
g-header-icon
。您缺少
a
。仍不清楚要单击哪个元素。路径
//previous sibling::span
非常没有意义-它会选择文档中某个元素的前一个同级元素。我怀疑前导“/”被添加为magic fairy dust,应该去掉。您需要提供一些匹配的节点才能得到好的答案。
WebElement pipeline = driver.findElement(By.xpath("//span[text()='Product']"));
WebElement parent = pipeline.findElement(By.xpath(".."));
WebElement sibling = parent.findElement(By.xpath("(//preceding-sibling::span[@class='g-header-icon ag-header-cell-menu-button']/span)[1]"));
sibling.click();
// Option 1
String xpath = "//div[div/span[@role='columnheader' and text()='Product']" + 
"//span[contains(@class, 'ag-icon-menu')]"

driver.findElement(By.xpath(xpath)).click();


// Option 2
String xpath = "//div[div/span[@role='columnheader' and text()='Product']"
driver.findElement(By.xpath(xpath))
      .findElement(By.cssSelector("span.ag-icon-menu"))
      .click()
driver.findElement(By.xpath("//span[contains(@class,'ag-icon') and contains(@class,'ag-icon-menu')]")).click();