Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/368.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 如何找到唯一代码的相对x路径?_Java_Xml_Selenium_Automation_Appium - Fatal编程技术网

Java 如何找到唯一代码的相对x路径?

Java 如何找到唯一代码的相对x路径?,java,xml,selenium,automation,appium,Java,Xml,Selenium,Automation,Appium,3个匹配节点。。它们都有相同的源代码。因此它失败了//img[(@src='/PHYLINSPortlet/images/override-0.gif')] 由于您没有共享HTML,因此提供问题的正确解决方案有点困难 当我观察问题中的图像时。您有3种相同类型的图像,并且希望单击任何特定的图像(比如第二个图像),然后您需要使用xpath方法,例如后面的兄弟姐妹或前面的兄弟姐妹,以使您的xpath唯一 示例:- 假设您的表中有任何唯一的列(规则id),或者您希望单击特定的图像。规则idVal0101

3个匹配节点。。它们都有相同的源代码。因此它失败了
//img[(@src='/PHYLINSPortlet/images/override-0.gif')]


由于您没有共享HTML,因此提供问题的正确解决方案有点困难

当我观察问题中的图像时。您有3种相同类型的图像,并且希望单击任何特定的图像(比如第二个图像),然后您需要使用
xpath
方法,例如
后面的兄弟姐妹
前面的兄弟姐妹
,以使您的
xpath
唯一

示例:-

假设您的表中有任何唯一的列(规则id),或者您希望单击特定的图像。规则id
Val01014
image

使用如下方法
xpath
-

//img[@src='/PHYLINSPortlet/images/override-0.gif']/preceding-sibling::td[text()='Val_01014']


如何查找唯一的xpath
id
属性对于每个元素都应该是唯一的。检查它是否是动态的(每次页面刷新后都会更改)所有3个按钮都是相同的。我在附加的图像上附加了图像,您使用
XPath
src
属性来查找元素。Try
id
id对于按钮是动态的。每个按钮都有唯一的id
    List<WebElement> buttons = driver.findElements(By.xpath("//img[(@src='/PHYLINSPortlet/images/override-0.gif')]"));
    for( WebElement button : buttons ) {
        button.click();
    }
//img[@src='/PHYLINSPortlet/images/override-0.gif']/preceding-sibling::td[text()='Val_01014']
//img[@src='/PHYLINSPortlet/images/override-0.gif']/following-sibling::td[text()='Val_01014']