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"));