Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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 XPath来选择前面的输入_Java_Selenium_Selenium Webdriver_Xpath_Siblings - Fatal编程技术网

Java XPath来选择前面的输入

Java XPath来选择前面的输入,java,selenium,selenium-webdriver,xpath,siblings,Java,Selenium,Selenium Webdriver,Xpath,Siblings,但是我想包括1.17,因为我们有很多AttachmentService,它们有不同的版本,比如1.15、1.16、1.17 如何处理此问题?您可以使用后面的同级添加具有特定版本的,并从该元素中使用前面的 driver.findElement(By.xpath("//td[contains(@title, AttachmentService')]//preceding::input[1]")) 使用以下同级 String version = "1.17"; driver.findElement(

但是我想包括
1.17
,因为我们有很多
AttachmentService
,它们有不同的版本,比如1.15、1.16、1.17


如何处理此问题?

您可以使用
后面的同级
添加具有特定版本的
,并从该元素中使用
前面的

driver.findElement(By.xpath("//td[contains(@title, AttachmentService')]//preceding::input[1]"))

使用
以下同级

String version = "1.17";
driver.findElement(By.xpath("//td[contains(@title, 'AttachmentService')]/following-sibling::td[.='" + version + "']//preceding::input[1]"));
结果:

String version = "1.17";
driver.findElement(By.xpath("//td[contains(@title, 'AttachmentService')]/following-sibling::td[.='" + version + "']//preceding::input[1]"));
driver.findElement(By.xpath("//td[following-sibling::td[@title='AttachmentService'] and following-sibling::td[text()='1.17']]/input"));