找不到带有 uiautomatorviewer 和 appium 的元素
Couldn't find an element with uiautomatorviewer and appium
我尝试使用 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. "}
我仍然不知道原因,但我通过这种方式解决了它:
driver.findElements(By.className("android.widget.TextView")).get(2).getText();
我尝试使用 uiautomatorviewer 和 运行 appium 版本 1.6.3,框架 TESTNG
为 Android 应用自动化脚本这里是我的代码,所有元素都很好找到,但只有最后一个索引为 2 的元素在 uiautomatorviewer 上可见(见图
@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. "}
我仍然不知道原因,但我通过这种方式解决了它:
driver.findElements(By.className("android.widget.TextView")).get(2).getText();