简体   繁体   中英

How to find an alert dialog through selenium using Appium?

A dialog is implemented in such way in the app:

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

How could I find this element in Appium testing script?

driver.switchTo().alert(); throws NotImplementError

driver.findElement(By.tagName("AlertDialog")) is not working

And I found this issue Alert methods NYI on Github. Is there any workaround about this?

By the way, I'm not going to click on "OK" or "Cancel" on that dialog, I'm about to wait until that dialog disappears automatically.

Thanks in advance.

Please use the below code for your need:

To wait for the alert to appear:

wait.until(ExpectedConditions.alertIsPresent());

To wait for the alert to disappear:

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

等待警报消失:

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

For me it works when I do this to accept alert dialog with OK button

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

But after the click action is completed my program stops detecting elements

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM