2

I am using nexus 5 to test. How can i choose image from gallery using appium in android. When i used following code :

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

I got such Exception:

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
Naman
  • 27,789
  • 26
  • 218
  • 353

3 Answers3

1

Try with this:

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

Try to write it with this manner it will select only the first :

  driver.findElement(By.xpath("//android.widget.ImageView[contains(@resource-id,'id of your image')]")).click();

With this code you can select any elements you want just put instead of i the element you want starting from 0 for the first one :

driver.findElements(By.xpath("//android.widget.ImageView[contains(@resource-id,‌​'id of your image')]")).get(i).click();
Emna Ayadi
  • 2,430
  • 8
  • 37
  • 77
0

The best way is to go by creating xpath!

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

Change your class name accordingly if different.

Emjey
  • 2,038
  • 3
  • 18
  • 33