how to handle alerts in android using appium

alert, android, appium

Solution

You need to get the Alert before you try and accept it

This is code from some of the Appium Java Client Tests:

wait.until(ExpectedConditions.alertIsPresent());
Alert alert = driver.switchTo().alert();
alert.accept();

This should work most of the time.

If `accept()` isn't working, replace the `driver.switchTo().alert();` and `alert.accept();` with code to find the button and then click it.

If it's not finding the button wrap `findElementBy(Method)` code in a try/retry block, and then click on it.

Problem

How do I handle alerts in an Android web application using Appium server (1.0.1) and the Android SDK? The below code is not working on android: ``` driver.switchTo().accept().alert(); ``` Error message: ``` > -modal window does not get closed ```

Original source