我是这个论坛和 appium/android 自动化的新手,我需要帮助来验证我的应用程序上是否存在对象,然后再采取下一步操作。
我尝试使用下面的代码,但甚至没有达到我的第二个打印语句。
@Test
public void addContact() {
System.out.println( "Checking if Contact exists.... 111111 ");
WebElement e = driver.findElement(By.name("John Doe"));
System.out.println( "Checking if Contact exists.... 222222");
boolean contactExists = e.isDisplayed();
System.out.println( contactExists );
if (contactExists == true) {
System.out.println( "Contact exists.... ");
} else {
System.out.println( "Contact DOES NOT exists.... ");
}
}
在 appium 控制台输出中运行此代码...它只是不断循环,并且脚本失败。
info: [BOOTSTRAP] [info] Got command of type ACTION
info: [BOOTSTRAP] [debug] Got command action: find
info: [BOOTSTRAP] [debug] Finding John Doe using NAME with the contextId:
info: [BOOTSTRAP] [info] Returning result: {"value":"No element found","status":7}
info: Pushing command to appium work queue: ["find",{"strategy":"name","selector":"John Doe","context":"","multiple":false}]
info: [BOOTSTRAP] [info] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"name","selector":"John Doe","context":"","multiple":false}}
isDisplayed 是正确的方法还是有更好的替代方法?
干杯......TIA
最佳答案
如果您使用的是 Appium 1.0+
- By.name 定位策略已被弃用。请使用其他一些东西,例如 By.xpath 等。
关于android - Appium - 如何验证对象是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24543079/