appium: Can't click on 'Allow' button on Notification popup at startup on IOS

The problem

When appium starts my app, I get a system notification popup at start up, regarding allowing, or not allowing my app to send notifications. There’s two buttons to choose from: “Don’t Allow” and “Allow”. In my Test I want to click on “Allow”. But seems Appium ckicks on the wrong one. “Don’t Allow”.

Environment

  • Appium version: 1.6.3
  • Desktop OS/version used to run Appium: Mac OSX 10.12.3 (Sierra)
  • Node.js version: 7.5.0
  • Mobile platform/version under test: IOS 10.2.1
  • Real device is used
  • Appium CLI, using Java client.

Details

By looking at my app, this appears to happen (while debug stepping my test):

Appium clicks twice, first time on “Don’t Allow” button, which causes the popup to dissapear. Then appium clicks again (instantly) on the location where the “Allow” button was, which happens to be the location of a “connect to facebook” button on my app.

Additionally: my app always runs in Landscape mode

Link to Appium logs

Appium logs: https://gist.github.com/alexander-poulikakos/c2547ea4cf990d7f1d2d079b77075561

Appium doctor:

$ appium-doctor --ios 
info AppiumDoctor Appium Doctor v.1.4.1
info AppiumDoctor ### Diagnostic starting ###
info AppiumDoctor  ✔ The Node.js binary was found at: /usr/local/bin/node
info AppiumDoctor  ✔ Node version is 7.5.0
info AppiumDoctor  ✔ Xcode is installed at: /Applications/Xcode.app/Contents/Developer
info AppiumDoctor  ✔ Xcode Command Line Tools are installed.
info AppiumDoctor  ✔ DevToolsSecurity is enabled.
info AppiumDoctor  ✔ The Authorization DB is set up properly.
info AppiumDoctor  ✔ Carthage was found at: /usr/local/bin/carthage
info AppiumDoctor  ✔ HOME is set to: /Users/alexanderpoulikakos
info AppiumDoctor ### Diagnostic completed, no fix needed. ###
info AppiumDoctor 
info AppiumDoctor Everything looks good, bye!
info AppiumDoctor  

Code To Reproduce Issue [ Good To Have ]

IOSDriver<IOSElement> appium = ...;
System.out.println(appium.getPageSource()); // I have a break point here to ensure the Notifications popup is visible before continuing 
IOSElement allow = appium.findElementByName("Allow");
System.out.println(allow.getText()); // See printout in log for this
System.out.println(allow.getLocation()); // See printout in log for this
new TouchAction(appium).tap(allow).perform();

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 28 (1 by maintainers)

Most upvoted comments

Try

driver.switchTo().alert().accept();
driver.switchTo().alert().dismiss();

methods to handle alerts

I’ve resolved this issue using:

driver.execute('mobile:alert', { action: 'accept' });

Modified working solution for Python: driver.execute_script('mobile: alert', {'action': 'accept', 'buttonLabel': 'Allow'}) parameter : buttonLabel is optional only for Accept/Dismiss Alert

I’m using something like this:

public static void acceptAllAlerts() { try { while (true) { log.info(“Checking for alerts and dismissing them.”); Thread.sleep(2000); // needed because in appium 1.4.8 accept() will choose the Deny. // Update list of alerts as needed if (Properties.IOS_VERSION.startsWith(“9”)) { Alert a = AppiumDriverInstance.getInstance().switchTo().alert(); try { AppiumDriverInstance.getInstance().findElement(By.id(Element.ALERT_OK_ALL_CAPITAL_NAME)) .click(); } catch (Throwable t) { throw new RuntimeException( "Alert displayed, but not handled in acceptAllAlerts (and it should be 😃 ) since this is iOS9 running on Appium 1.4.8. Alert: " + a.getText()); } } else { AppiumDriverInstance.getInstance().switchTo().alert().accept(); } } } catch (Throwable t) { // do nothing } }