Skip to content Skip to sidebar Skip to footer

Can't Click Allow Button In Permission Dialog In Android Using Appium

I am unable to tap on Deny or Allow buttons on the permissions dialog in Android using Appium+Java. Do I need to add any capabilities before going to tap on those buttons? Below is

Solution 1:

Use full resource ID ...It worked for me....

below line worked for me.... driver.findElement(MobileBy.id("com.android.packageinstaller:id/permission_allow_button")).click();

Solution 2:

With the below snippet I am able to click on all the allow buttons to get the permissions.

while (driver.findElements(MobileBy.xpath("//*[@class='android.widget.Button'][2]")).size()>0) {
    driver.findElement(MobileBy.xpath("//*[@class='android.widget.Button'][2]")).click();
}

Solution 3:

Starting from appium 1.6.3 you can just add:

capabilities.setCapability("autoGrantPermissions", "true");

And you'll always allow all permissions your app wants.

Solution 4:

Appium gives you an API that detect the activity. Depending upon your device, you could get two activities - the package name may get stripped off or not:

'com.android.packageinstaller.permission.ui.GrantPermissionsActivity',
'.permission.ui.GrantPermissionsActivity'

After detecting this activity, you need to find an element by locator(id/xpath):

'com.android.packageinstaller:id/permission_message'

Then you can obtain the text of that message if you are interested in it. If you care which permission it is, you can match it against expected strings or regular expressions. If not, you can blindly accept by finding and clicking the element by id:

'com.android.packageinstaller:id/permission_allow_button'

If you'd rather not click 'allow' on all those windows, you can use adb to add all the permissions at once before you start testing (but after Appium has installed your app). If you know all the perms your app will need, you can add them with one command:

pm grant $app_name$space_delimited_set_of_perms

Or you can add all permissions one at a time, which takes 1.5-2 seconds per attempt.

Reference : https://discuss.appium.io/t/android-m-and-permissions/5760/13

Solution 5:

I tried lot many solutions before I found what is the fix. I had enabled Touch ball / quick ball feature and icon used stay always on the screen to help me navigate.

This app was the culprit which had overlay feature enabled and wasn't easy to figure it out by browsing the active apps under the installed apps.

Note: Mine was MIUI 11 with Android 7 for Redmi Note 4.

Post a Comment for "Can't Click Allow Button In Permission Dialog In Android Using Appium"