1

I am using Appium with C# client.

When launching an Android app, I get several permission dialogue boxes like this one.

Android Screenshot

I would like to click on "Allow" or "Deny" buttons, which I am unable to do using below code.

var Allow_Btn = driver.FindElementById("permission_allow_button");
Allow_Btn.Click();

After a lot of googling, I found out that we can skip these permissions by using the below capability.

Capability.SetCapability("autoGrantPermissions", "true");

But I would like to know if there is any other way to do it.

Thanks in advance.

2 Answers 2

1

I don't know where did you get this permission_allow_button ID, I don't think the locator is correct.

Here is how it looks like for me in Android Device Monitor application

enter image description here

So if you still want to use the strategy of finding the element by ID - you should use com.android.packageinstaller:id/permission_allow_button ID.

Another option is going for XPath selectors like:

  • //Button[@text()='ALLOW]
  • //Button[@resource-id='com.android.packageinstaller:id/permission_allow_button']
Sign up to request clarification or add additional context in comments.

1 Comment

I usually use the ID that way and it works every time. Below is the app that I am using to test. apkpure.com/raaga/net.amp.raaga/download?from=details Below techniques didn't work. driver.FindElement(new ByAndroidUIAutomator("text(\"ALLOW\")")).Click(); driver.FindElementById("com.android.packageinstaller:id/permission_allow_button"); driver.FindElementByXPath("//*[@class='android.widget.Button'][2]").Click();
0

You can do it by Xpath locators only. Find by id would not worked for permission dialog handling. To find "ALLOW" button you can use

driver.find_element_by_xpath("//*[@class='android.widget.Button'][2]") //it denotes "Allow" button

and for "DENY" button you,

driver.find_element_by_xpath("//*[@class='android.widget.Button'][1]") //it denotes "Deny" button

Before you click the button you should wait until the element located

WebDriverWait wait = new WebDriverWait(driver, timeOut);                
wait.until(ExpectedConditions.presenceOfElementLocated(element));

Hope this will help you.

3 Comments

Thanks Mohanraj for your reply. Could you please try on this app at apkpure.com/raaga/net.amp.raaga/download?from=details. Let me know if it works for you as none of the below techniques work for me. driver.FindElement(new ByAndroidUIAutomator("text(\"ALLOW\")")).Click(); driver.FindElementById("com.android.packageinstaller:id/permission_allow_button"); driver.FindElementByXPath("//*[@class='android.widget.Button'][2]").Click();
@Abhi3106 I used it in my application and worked as expected and fine.
Would you mind giving a try on that app and share your results. It would be helpful. Thank You.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.