我目前的情况是需要从 child 中选择 parent 。 child 有 id,但 parent 没有。所以这实际上是为数不多的解决方案之一。
WebElement child = driver.findElement(By.id("books"));
System.out.println(child.getAttribute("name")); //prints correct node
WebElement parent = child.findElement(By.xpath(".."));
System.out.println(parent.getAttribute("name")); // error can't find element
最佳答案
在Appium中,要选择直接父节点,需要提供/..
例如 childElement Xpath =//android.widget[@text='name']
父 Xpath 表达式: mobiledriver.FindElement(By.xpath("//android.widget[@text='name']/..").click
关于java - appium - 选择父节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40891710/