'Appium: automatically handling the iOS location permissions popup

I need to be able to either prevent the location permissions popup from occurring or have it handled by Appium/WebDriver. It looks like the Appium settings API supports these two settings for this purpose:

appium:autoAcceptAlerts

and

acceptAlertButtonSelector

We're using Java and unless I'm mistaken, settings have to be applied via a driver instance, something like this:

driver.setSetting("appium:autoAcceptAlerts",true);

The problem that I have is that when creating the driver instance, we have to pass in the capabilities that we require. In practice, this seems to mean that by the time the instance has been created, the application has already launched and the location permissions popup is already on display before we can set the appropriate settings.

I'm sure I must be missing something so I'd appreciate it if anyone can point out my mistake

TIA, Mike



Solution 1:[1]

You can Try this in your capabilities setting:

capabilities.setCapability("autoAcceptAlerts", "true"); // for auto alerts
capabilities.setCapability("autoGrantPermissions", "true"); // for auto premission

or you can try manual handle with this: custom element when you needed with alert displayed

public void alertAction(String action) {
        By element;
        switch (action.toUpperCase()) {
            case "DONT ALLOW":
                element = MobileBy.id("Don’t Allow");
                break;
            case "ALLOW":
                element = MobileBy.id("Allow");
                break;
            case "ASK APP NOT TO TRACK":
                element = MobileBy.id("Ask App Not to Track");
                break;
            case "OK":
                element = MobileBy.id("OK");
                break;
            case "TONTON SEKARANG":
                element = MobileBy.id("Tonton Sekarang");
                break;
            case "CANCEL":
                element = MobileBy.id("CANCEL");
                break;
            case "LOGOUT":
                element = MobileBy.id("LOG OUT");
                break;
            default:
                throw new IllegalStateException("Unexpected value: " + action.toUpperCase());
        }
        if (isPresent(element)) {
            clickOn(element);
        }
    }

this work for me on appium version 1.21.0, and iOS version 15

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Fransiskus Andika Setiawan