Can't click Allow button in permission dialog in Android using Appium

后端 未结 5 1781
予麋鹿
予麋鹿 2021-02-08 21:30

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

相关标签:
5条回答
  • 2021-02-08 22:03

    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

    0 讨论(0)
  • 2021-02-08 22:09

    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();

    0 讨论(0)
  • 2021-02-08 22:16

    Starting from appium 1.6.3 you can just add:

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

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

    0 讨论(0)
  • 2021-02-08 22:24

    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();
    }
    
    0 讨论(0)
  • 2021-02-08 22:25

    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.

    0 讨论(0)
提交回复
热议问题