NoSuchElementException:无法从库中选择图像

时间:2016-05-17 11:00:59

标签: appium nosuchelementexception

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

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

我有这样的例外:

Exception in thread "main"
org.openqa.selenium.NoSuchElementException: An element could not be
located on the page using the given search parameters. (WARNING:The
server did not provide any stacktrace information) Command duration
or timeout: 50.56 seconds

3 个答案:

答案 0 :(得分:1)

试试这个:

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

答案 1 :(得分:0)

尝试用这种方式编写它只会选择第一个:

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

答案 2 :(得分:0)

最好的方法是创建xpath!

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

如果不同,请相应地更改您的班级名称。

相关问题