Appium NoTouchElementException:无法从库中选择图像

Appium NoTouchElementException:无法从库中选择图像,appium,nosuchelementexception,Appium,Nosuchelementexception,我正在使用Nexus5进行测试。如何在android中使用appium从图库中选择图像。当我使用以下代码时: driver.findElement(By.xpath("//android.widget.ImageView[@content-desc='Photo taken on 13 May 2016 12.50']")).click(); 我有这样的例外: 尝试以这种方式写入,它将仅选择第一个: driver.findElement(By.xpath("//android.wi

我正在使用Nexus5进行测试。如何在android中使用appium从图库中选择图像。当我使用以下代码时:

driver.findElement(By.xpath("//android.widget.ImageView[@content-desc='Photo
    taken on 13 May 2016 12.50']")).click();
我有这样的例外:


尝试以这种方式写入,它将仅选择第一个:

  driver.findElement(By.xpath("//android.widget.ImageView[contains(@resource-id,'id of your image')]")).click();
使用此代码,您可以选择要放置的任何元素,而不是从0开始选择第一个元素:

driver.findElements(By.xpath("//android.widget.ImageView[contains(@resource-id,‌​'id of your image')]")).get(i).click();
试试这个:

driver.findElement(By.xpath("//*[@class='android.widget.ImageView' and @content-desc='Photo taken on 13 May 2016 12.50']")).click();

最好的方法是创建xpath

 find_element(xpath: "//android.widget.FrameLayout[1]").click

如果不同,请相应地更改您的类名。

Emma感谢您编写的代码,它对我有用,但唯一的问题是它只选择第一个图像欢迎,很高兴;)(我不是Emna,不是Emma haha)我有一个很酷的主意,让你选择任何元素,试着编译这段代码,取而代之的是我放入你想要的任何元素,例如当i=0时,它是第一个元素:
driver.findElements(By.xpath(//android.widget.ImageView[contains(@resource id,'id of your image'))))))。get(i)。click() find_element(xpath: "//android.widget.FrameLayout[1]").click