UI Automator viewerI have tried few things to click on "OK" button for location permission Popup on Android:

  1. With MobileBy.
  2. With By locator.
  3. By adding capabilities mentioned on other solutions.

But nothing is working.

driver.findElement(By.xpath("//*[@id='button1']")).click();

2 Answers

2
akshay patil On Best Solutions

As you have shared the screenshot thank you for that can you please try the xpath

Xpath:

driver.findElement(By.xpath("//android.widget.Button[@text='OK']")).click();

and let us know...^.^

2
Suban Dhyako On

For your app you can click ok using:

driver.findElementById("android:id/button1").click();

using xpath is not recommended in appium.

For android System permission pop up you can allow/deny permission by:

//to allow permission
driver.findElementById("com.android.packageinstaller:id/permission_allow_button").click();

//to deny permission
driver.findElementById("com.android.packageinstaller:id/permission_deny_button").click();

For ios system permission popup you can allow/deny permission by:

//to allow permission
driver.findElementByAccessibilityId("OK").click();

//to deny permission
driver.findElementByAccessibilityId("Don’t Allow").click();

You can also use add autoGrantPermissions=true (for android) and autoAcceptAlerts=true (for ios) capability in your DesiredCapabities.