I tried to automate scripts for Android app using uiautomatorviewer and running appium version 1.6.3, framework TESTNG
Here My code, all element are well found, but only the last one with index = 2 it's visible on uiautomatorviewer (see the picture) All elemnt with index 0 and 1 are found ok ! only the last one. I'm using the same logic just changing the index with 2
@Test(priority = 1)
public void SignIn() throws InterruptedException {
System.out.println("newlook-tutoriel");
/*
* boolean ispresent = driver.findElement(By.id("skip")).isDisplayed();
* if (ispresent == true) { driver.findElement(By.id("skip")).click();
* System.out.println("Tutorials are present"+ispresent); } else
* System.err.println("Tutorials aren't present ! "+ispresent);
*/
System.out.println("newlook-welcome");
driver.findElement(By.id("btn_signin_welcome")).click();
System.out.println("newlook-Me connecter");
driver.findElement(By.id("input_email")).sendKeys(
"eayadi@bulldozerinc.com");
System.out.println(driver.findElement(By.id("input_password"))
.getClass());
// Thread.sleep(5000);
driver.hideKeyboard();
driver.findElement(By.id("input_password")).sendKeys("00000000");
// Thread.sleep(5000);
driver.hideKeyboard();
driver.findElement(By.id("btn_signin")).click();
Thread.sleep(5000);
System.out.println("connected !!!!");
System.out.println(driver.findElement(By.xpath(".//@class='android.widget.TextView'")).getText());
System.out.println("Bienvenue"+driver.findElement(By.xpath("//*[@class='android.widget.TextView' and @index='0']")).getText());
System.out.println("Emna"+driver.findElement(By.xpath("//*[@class='android.widget.TextView' and @index='1']")).getText());
System.out.println("répondez....." + driver.findElement(By.xpath("//*[@class='android.widget.TextView' and @index='2']")).getText());
driver.findElement(By.xpath("//*[@class='android.widget.Button']")).click();
}
Here appium log
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//*[@class='android.widget.TextView' and @index='2']","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//*[@class='android.widget.TextView' and @index='2']","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding '//*[@class='android.widget.TextView' and @index='2']' using 'XPATH' with the contextId: '' multiple: false
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":7,"value":"Could not find an element using supplied strategy. "}
I still don't know the reson but i resolve it by this way :
driver.findElements(By.className("android.widget.TextView")).get(2).getText();