Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 295
Roy Xiang Avatar asked Sep 12 '25 16:09

Roy Xiang


1 Answers

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());
like image 142
Abhishek Swain Avatar answered Sep 14 '25 06:09

Abhishek Swain