How to handle pop-ups in mobile apps

I am attempting to set up my first test, by logging into my app and then logging back out. After I log in, a pop up appears asking me to either confirm some information or “ask me later.” I’m using the Appium Desktop inspector to get the ID of the button in the popup, but nothing has seemed to work.
I’ve tried every findElementBy method, as well as the driver.switchTo().alert(). I have also added “autoGrantPermissions”, “true” and “autoAcceptAlerts”, “true” in my desired capabilities. How can I remedy this? Thanks!

Extra Notes:
-Using Appium Version 1.8.1
-Tests written in java (and all path variables have been set correctly)
-App in android and is being ran on an on Android Emulator
-I use macOS High Sierra

you can use uiautomatorviewer to capture the resource id or text attribute and then use click to handle the Alerts.

uiautomatorviewer comes with android sdk and is present in tools folder. I suggest capture the locator using a real device.

autoAcceptAlerts is deprecated.

1 Like

Venkatesh,

Thanks for the reply! I have tried using the UIAutomatorViewer to capture ID, class name, xpath, name, etc. to use the various findElementBy methods, but still nothing is allowing me to click on popup elements.

Here is the output I’m getting after running my test and the popup is unsuccessfully clicked:

at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:89)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:317)
at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:62)
at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:419)
at io.appium.java_client.DefaultGenericMobileDriver.findElementByXPath(DefaultGenericMobileDriver.java:140)
at io.appium.java_client.AppiumDriver.findElementByXPath(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.findElementByXPath(AndroidDriver.java:1)
at io.appium.java_client.android.LoginTest.loginToApp(LoginTest.java:47)
at io.appium.java_client.android.MainTest.loginLogout(MainTest.java:70)
at io.appium.java_client.android.MainTest.main(MainTest.java:28)

I have the same problem … I already tried by ID, Xpath, Class everything that is possible … By Ispector of Appium I can capture the element and click, playing the same code in ruby / cucumber does not work … says no able to locate the element.

Can anyone help? application was developed in IONIC with Angular