How to handle native iOS Alerts in Appium using Ja

2020-04-16 02:48发布

问题:

I try to write tests for an app, which shows iOS native alert for Location (This app would like to use your current location). I tried this code

driver.switchTo().alert.accept();

This actually works for other alerts, but not for native ones.

Also I noticed, that since 2nd time I run a test(even there is nothing but an sysout), it fails because of SessionNotCreatedException, but if I remove that alert from app, everything is ok.

I use Appium 1.3.4. Thanks in advance.

回答1:

Try adding to your Desired Capabilities ("autoAcceptAlerts",true). It doesn't work perfectly but you should try it.

You can also try doing:

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

Hope this helps.