Cannot click the Allow button in the Permissions dialog on Android using Appium

I cannot use the Deny or Allow buttons in the Permissions dialog on Android using Appium + Java. Do I need to add any features before clicking on these buttons? Below is the code:

DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("platformName", "Android"); capabilities.setCapability("deviceName", "ASUS_Z00LD"); capabilities.setCapability("platformVersion", "6.0"); capabilities.setCapability("app","<AppPath>"); capabilities.setCapability("browserName", ""); AndroidDriver<MobileElement> driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); Thread.sleep(10000); driver.findElement(MobileBy.id("permission_allow_button")).click(); 

The following is the error in the Eclipse console:

 org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information) 

Below is the Appium magazine:

 info: [debug] Responding to client with success: {"status":0,"value":{"platform":"LINUX","browserName":"","platformVersion":"6.0.1","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"app":"/Users/Shiva/Documents/workspace/AndroidPractice/APK/Motiv_Android.apk","browserName":"","platformName":"Android","deviceName":"ASUS_Z00LD","platformVersion":"6.0"},"app":"/Users/Shiva/Documents/workspace/AndroidPractice/APK/Motiv_Android.apk","platformName":"Android","deviceName":"FAAZCY127084"},"sessionId":"b64fd5af-3de5-4299-a2d4-1948fc8e883e"} info: <-- GET /wd/hub/session/b64fd5af-3de5-4299-a2d4-1948fc8e883e 200 1.534 ms - 625 {"status":0,"value":{"platform":"LINUX","browserName":"","platformVersion":"6.0.1","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"app":"/Users/Shiva/Documents/workspace/AndroidPractice/APK/Motiv_Android.apk","browserName":"","platformName":"Android","deviceName":"ASUS_Z00LD","platformVersion":"6.0"},"app":"/Users/Shiva/Documents/workspace/AndroidPractice/APK/Motiv_Android.apk","platformName":"Android","deviceName":"FAAZCY127084"},"sessionId":"b64fd5af-3de5-4299-a2d4-1948fc8e883e"} info: --> POST /wd/hub/session/b64fd5af-3de5-4299-a2d4-1948fc8e883e/element {"using":"id","value":"permission_allow_button"} info: [debug] Waiting up to 0ms for condition info: [debug] Pushing command to appium work queue: ["find",{"strategy":"id","selector":"permission_allow_button","context":"","multiple":false}] info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"permission_allow_button","context":"","multiple":false}} info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION info: [debug] [BOOTSTRAP] [debug] Got command action: find info: [debug] [BOOTSTRAP] [debug] Finding permission_allow_button using ID with the contextId: multiple: false info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.shure.motiv:id/permission_allow_button] info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=android:id/permission_allow_button] info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[DESCRIPTION=permission_allow_button, INSTANCE=0] info: [debug] [BOOTSTRAP] [debug] Failed to locate element. Clearing Accessibility cache and retrying. info: [debug] [BOOTSTRAP] [debug] Finding permission_allow_button using ID with the contextId: multiple: false info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.shure.motiv:id/permission_allow_button] info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=android:id/permission_allow_button] info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[DESCRIPTION=permission_allow_button, INSTANCE=0] info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":7,"value":"No element found"} info: [debug] Condition unmet after 178ms. Timing out. info: [debug] Responding to client with error: {"status":7,"value":{"message":"An element could not be located on the page using the given search parameters.","origValue":"No element found"},"sessionId":"b64fd5af-3de5-4299-a2d4-1948fc8e883e"} info: <-- POST /wd/hub/session/b64fd5af-3de5-4299-a2d4-1948fc8e883e/element 500 181.769 ms - 195 

Anyone help overcome this will be appreciated?

+7
java android selenium selenium-webdriver appium
source share
4 answers

In the snippet below, I can click on all allow buttons to get permissions.

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

Use full resource id ... This worked for me ....

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

+5
source share

Appium provides an API that defines activity. Depending on your device, you can get two actions - the package name can be disabled or not:

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

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

 'com.android.packageinstaller:id/permission_message' 

Then you can get the text of this message if you are interested in it. If you are wondering what permission this is, you can match it with expected strings or regular expressions. If not, you can blindly accept by finding and clicking on an element by id:

 'com.android.packageinstaller:id/permission_allow_button' 

If you do not want to click "allow" on all of these windows, you can use adb to add all permissions right before testing starts (but after Appium has installed your application). If you know all the applications you need, you can add them with a single 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.

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

0
source share

Starting with appium 1.6.3 you can simply add:

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

And you will always allow all permissions that your application requires.

0
source share

All Articles