android - Appium - 如何验证对象是否存在

标签 android appium

我是这个论坛和 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/

相关文章:

java - Appium - 关于用 Java 编写测试的问题

android - 使用 SkiaSharp 在 Xamarin 中加载 SVG 文件

android - 在 jitpack 中获取 'buildscript {} blocks must appear before any plugins {} blocks' 错误

java - 分数计数器不增加

android - Flutter布局不一致

java - Appium + Saucelabs 集成(JAVA)错误

java - 实现 ViewModelProvider.Factory 时出现空指针异常

android - 如何将 Android 设备连接为 Jenkins 从站以执行自动测试

java - 使用 AccessibilityId 按部分字符串查找元素

linux - 无法在Ubuntu上安装appium