IOS alerts:Handle system alerts in IOS Simulator

Hi All,

I want to handle the IOS alerts in simulator.
Ex:
When i install my app in simulator(iPhone 4s) then it is throwing message “This app allowing to access the current location” with Agree and Dont Agree. I want to click on either Agree or Don’t agree but how?

Java:

           System.out.println("   wait to dismiss any system location dialogs");
            WebDriverWait wait = new WebDriverWait(driver, 10);
            try {
                wait.until(ExpectedConditions.alertIsPresent());
                driver.switchTo().alert().accept();
            } catch (Exception e) {
                System.err.println("   no alert visible after 10 sec.");
            }
1 Like

In iPhone, When you install the IOS apps like ola or Uber then one message is displays like
“Allow XXXXXX to access your location for searching cabs near you” with the following buttons
Dont Allow and Allow but how can identify the properties of this object using appium tool.

on real phone - no way

Yes in real phone…is there anyway for simulator?

on simulator try posted code to accept or decline.
you can also get pagesource and search by class for something like “UIAlert”

How can get page source here?it is system throwing message(ALerts from system level)

well if you are not even to start driver = no way. is it your case?
regarding “it is system throwing message” - it is visible in Appium inspector and pagesource with Simulator.

Hi Aleksei,

This message thrown by IOS (System level) so we can not see the properties in page source also.

only with real device! with Simulator it is visible.

hi

Can you tell me the solution for the following?

I installed one app in my mobile and i want to sign up via gmail or twitter then i click on anyone and selected particular screen opened. Now i want to identify the element properties in newly displayed screen.

I use the ‘page’ command:

http://appium.io/slate/en/tutorial/ios.html?java#page-command

And then search the results. If I was on a screen that had an Alert (popup), I would look for ‘UIAAlert’, and then accept or dismiss it. I also use these results to identify the page I’m on. To find individual elements I still do a find by or such.

note that there are 2 kinds of alert:

  • system alert like allow use location to application
  • alert that is application use in code. this alert is absolutely look like system but generated application and THUS not visible if you are not automating (owner) of this application.

Hi Kranthi,

Even I need help as my app redirects to facebook login page. Where you able to handle it? So even I am facing the issue on the same so how can I handle this

@Aleksei thanks for sharing this, had spent lot of time figuring out how to click on a custom button on pop-up in iOS simulator.

Note for others:
Similar to selenium, it is necessary to set focus to current pop-up and then do action on it.

is there anyway i can do this in ruby? appium 1.6.3

no idea - check here https://github.com/appium/ruby_lib/blob/master/ios_tests/lib/ios/specs/ios/element/alert.rb

iOS 11.0 solution using advanced gesture mobile: alert

https://appium.readthedocs.io/en/stable/en/writing-running-appium/ios-xctest-mobile-gestures/

But first check need to be optimized, as it’s quite slow because of xpath, any solution for this check ?

if(getDriver().findElements(By.xpath("//XCUIElementTypeAlert[contains(@name,'access your location while you are using the app')]")).size()  ) {
                JavascriptExecutor js = (JavascriptExecutor) getDriver();
                HashMap<String, String> tapObject = new HashMap<String, String>();
                tapObject.put("action", "accept");
                tapObject.put("label", "Allow");
                js.executeScript("mobile:alert", tapObject);
              }