How to handle App permission pop ups (system popups like device location/contact list) in Appium android tests for OS Marshmallow and above?

PFB the code:

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, ""); //Name of mobile web browser to automate. Should be an empty string if automating an app instead.
capabilities.setCapability(CapabilityType.VERSION, "6.0");
capabilities.setCapability(CapabilityType.PLATFORM, "Android");
capabilities.setCapability("deviceName", <deviceID>);
capabilities.setCapability("locationServicesAuthorized", true);
capabilities.setCapability("appPackage",<Package Name for app under test >); //Replace with your app's package	
capabilities.setCapability("appActivity",<Activity Name for app under test >); //Replace with app's Activity
driver = new AndroidDriver<AndroidElement>(new URL(""), capabilities);

When the app under test gets launched for the first time, it displays a Location permission popup.
The resource id for popup element is:
which is outside package of app under test.
We are able to detect the elements of App permission pop up using uiAutomatorViewer.
But, we are unable to run script using the same element ids as those are not getting detected through the script.

We tried using below code:

**capabilities.setCapability("autoAcceptAlerts", true);**

This is not working.

We have even tried using:
This also is not working.

Any suggestions will be appreciated.

Yeah… probably these alerts might be coming while your application contains maps. So, there are two possible ways to handle those.

  1. Turn off GPS setting on your test device.
  2. Switch between contexts by using driver.context… and you can identify those alert’s properties by UIAutomatorviewer too.

Happy Testing !! :smile:

Vijay Bhaskar.

Hi @bhaskar,

Thanks for the reply but it didn’t work…
Even if we turn off GPS setting on our test device, we are getting GPS permission pop up on app launch.

Unfortunately, autoAcceptAlerts works only for iOS.

And, driver.switchTo().a‌​lert().accept(); works only for web view.

I am using Appium Inspector to find elements. The below code work for native app -

WebElement allowButton = driver.findElements(By.xpath("//android.widget.Button[@resource-id=''])"));;

Not working, is there anything which can avoid such pop up for getting being dislayed

Hi Shruti,

I used the below code for the android Version 5.1 and its working perfectly for me.


1 Like

If you want to allow all the permissions to the app you are going to install, then you can auto grant all the permissions through DesiredCapability.
capabilities.setCapability(“autoGrantPermissions”, true);
This will not open the permission popup when the app is installed and launched.


Hi @Rohan1808 it’s work for me, I also face the same issue using API 23. Thanks for sharing

This capabilities worked for me:

caps = {}
caps[“platformName”] = “Android”
caps[“platformVersion”] = “7.0”
caps[“deviceName”] = “Pixel_C_API_24”
caps[“automationName”] = “UiAutomator2”
caps[“app”] = “/home/tests/app-debug.apk”
caps[“noReset”] = False
caps[“autoGrantPermissions”] = True
caps[“appPackage”] = “com.mypackage”
caps[“appActivity”] = “.MyActivity”


Thanks it worked for me on Android version “Q”

This would work.

final WebElement allowButton = driverAndroid.findElement(“”));;

final WebElement denyButton = driverAndroid.findElement(“”));;

driver.switchTo().alert().accept(); worked for me on a native app. The trick was first adding a wait to make sure the alert existed.

WebDriverWait wait = new WebDriverWait(driver, 5);
1 Like

Hi @Rohan1808 i have used this code but after giving permissions my code is not working for further steps and even in console i am not getting any error , do i need to change view after giving permissions

Hi Rohan,
Will it work for both iOS and Android??

I used the following capabilities in my appium code but still my location pop is not disappearing.
caps.setCapability(“enablePerformanceLogging”, true);
caps.setCapability(“extendedDebugging”, true);
caps.setCapability(“locationContextEnabled”, true);
caps.setCapability(“autoAcceptAlerts”, “true”);
caps.setCapability(“locationServicesAuthorized”, false)