我尝试使用 uiautomatorviewer 并运行 appium 版本 1.6.3、框架 TESTNG 为 Android 应用程序自动化脚本
在这里我的代码,所有元素都很好找到,但只有最后一个索引 = 2 它在 uiautomatorviewer 上可见(见图)所有索引为 0 和 1 的元素都可以找到!只有最后一个。我使用相同的逻辑只是用 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();
}
这里appium日志
[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. "}