Unable to click on system popup iOS


I am trying to automate tests for web application in Safari browser. I have a case where after clicking on some WebElement system iOS popup has been triggered. I am trying to click on this with several ways but wihout effect. Unfortunately design of how it is handled is very annoying because to handle this popup I need to use try catch block because exception is raised under the click method. But as I said I am able to handle this with try catch so this is what I am already tried.

First approach:
Driver.SwitchTo().Alert().Accept(); and Driver.SwitchTo().Alert().Dismiss();

In Appium I can see following output:
[debug] [W3C (54e1d035)] Calling AppiumDriver.getAlertText() with args: [“54e1d035-fbb1-4cc3-93a2-40e0399d97ab”]
[debug] [XCUITest] Executing command ‘getAlertText’
[debug] [W3C (9a8f5d54)] Encountered internal error running command: Error: Did not get any response after 300s

As you see there is no response and my test is crashed without dismiss or accepting alerts.

Second approach
Dictionary<string, string> dictionary = new Dictionary<string, string>();
dictionary.Add(“action”, “accept”);
dictionary.Add(“label”, “Allow”);
IJavaScriptExecutor js = (IJavaScriptExecutor)driverWrapper.Driver;
js.ExecuteScript(“mobile:alert”, dictionary);

I am also gave a try following line instead of second line in the snippet:
dictionary.Add(“action”, “postAcceptAlert”);

In Appium I can see following output:
[HTTP] {“script”:“mobile:alert”,“args”:[{“action”:“postAcceptAlert”,“label”:“Allow”}]}
[debug] [W3C (f3df7c18)] Calling AppiumDriver.execute() with args: [“mobile:alert”,[{“action”:“postAcceptAlert”,“label”:“Allow”}],“f3df7c18-3e4b-4574-8004-d29b9db6a2b7”]
[debug] [XCUITest] Executing command ‘execute’

And it have timeout after 60 seconds.

Someone can help me? I am already waste 2 days for this annoying case.

Finally, I found the solution. Solution is tricky - to click on the alert you have to switch to NATIVE_APP context. No one is writing about it on the Internet. Unfortunately solution is terribly slow because you have to wait for WebDriverException which are throwed after 60 seconds by default. Sample code in C# which solve the issue for me:

var appiumDriver = (AppiumDriver<AppiumWebElement>)driverWrapper.Driver;
var currentContext = appiumDriver.Context;
catch (WebDriverException)
appiumDriver.Context = “NATIVE_APP”;
appiumDriver.Context = currentContext;
1 Like