【问题标题】:How to find an alert dialog through selenium using Appium?如何使用 Appium 通过 selenium 找到警报对话框?
【发布时间】:2014-03-25 19:35:06
【问题描述】:

在应用程序中以这种方式实现对话框:

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Something");
builder.setTitle("Something");
dialog = builder.create();
dialog.show();

如何在 Appium 测试脚本中找到这个元素?

driver.switchTo().alert(); 抛出NotImplementError

driver.findElement(By.tagName("AlertDialog")) 不工作

我在 Github 上发现了这个问题 Alert methods NYI。有什么解决方法吗?

顺便说一句,我不会在那个对话框上点击“确定”或“取消”,我要等到那个对话框自动消失。

提前致谢。

【问题讨论】:

    标签: java selenium android-testing appium


    【解决方案1】:

    请根据您的需要使用以下代码:

    等待警报出现:

    wait.until(ExpectedConditions.alertIsPresent());
    

    等待警报消失:

    wait.until(!ExpectedConditions.alertIsPresent());
    

    【讨论】:

      【解决方案2】:

      对我来说,当我这样做以接受带有确定按钮的警报对话框时,它会起作用

      driver.findElement(By.name("OK")).click()
      

      但是点击动作完成后我的程序停止检测元素

      【讨论】:

      • 他们不想关闭警报,他们需要等到它自动关闭。
      【解决方案3】:

      等待警报消失:

      wait.until(ExpectedConditions.not(ExpectedConditions.alertIsPresent()));
      

      【讨论】:

        猜你喜欢
        • 2015-12-16
        • 1970-01-01
        • 1970-01-01
        • 2018-08-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-09-23
        相关资源
        最近更新 更多