Unable to accept iOS permission alerts from appium automation code

Unable to accept Noification permission alert via appium automation code
Tried multiple ways but could not resolve the issue.

06%20PM

Logs are below

[35m[HTTP]e[39m e[90m{“script”:“mobile: alert”,“args”:[{“action”:“accept”}]}e[39m
[debug] e[35m[W3C (d1a96719)]e[39m Calling AppiumDriver.execute() with args: [“mobile: alert”,[{“action”:“accept”}],“d1a96719-2204-427a-ae6d-3d3a175b6b7e”]
[debug] e[35m[XCUITest]e[39m Executing command ‘execute’
[debug] e[35m[WD Proxy]e[39m Matched ‘/alert/accept’ to command name ‘postAcceptAlert’
[debug] e[35m[WD Proxy]e[39m Proxying [POST /alert/accept] to [POST http://127.0.0.1:8200/session/3E11ED17-1B72-4424-9F3F-1583EB59287A/alert/accept] with body: {}
e[35m[WD Proxy]e[39m Got response with status 500: {“value”:{“error”:“unknown error”,“message”:"* -[__NSArrayM insertObject:atIndex:]:** object cannot be nil",“traceback”:"(\n\t0 CoreFoundation 0x000000018083d110 16FAA70C-278C-3561-859E-CEC407C2DC7C + 626960\n\t1 libobjc.A.dylib 0x0000000199078d64 objc_exception_throw + 60\n\t2 CoreFoundation 0x0000000180946564 16FAA70C-278C-3561-859E-CEC407C2DC7C + 1713508\n\t3 CoreFoundation 0x00000001809437e0 16FAA70C-278C-3561-859E-CEC407C2DC7C + 1701856\n\t4 CoreFoundation 0x00000001807b1a5c 16FAA70C-278C-3561-859E-CEC407C2DC7C + 55900\n\t5 XCUIAutomation 0x0000000100e5ffa8 __104-[XCAXClient_iOS interruptingUIElementsAffectingSnapshot:checkForHandledElement:containsHandledElement:]_block_invoke + 1012\n\t6 XCTestCore 0x000000010089bff0 -[XCTContext _runActivityNamed:type:block:] + 256\n\t7 XCTestCore 0x000000010089b184 +[XCTContex…
[debug] e[35m[W3C]e[39m Matched W3C error code ‘unknown error’ to UnknownError
[debug] e[35m[W3C (d1a96719)]e[39m Encountered internal error running command: UnknownError: An unknown server-side error occurred while processing the command. Original error: *** -[__NSArrayM insertObject:atIndex:]: object cannot be nil
[debug] e[35m[W3C (d1a96719)]e[39m at errorFromW3CJsonCode (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/errors.js:780:25)
[debug] e[35m[W3C (d1a96719)]e[39m at ProxyRequestError.getActualError (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/errors.js:663:14)
[debug] e[35m[W3C (d1a96719)]e[39m at JWProxy.command (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/jsonwp-proxy/proxy.js:272:19)
[debug] e[35m[W3C (d1a96719)]e[39m at runMicrotasks ()
[debug] e[35m[W3C (d1a96719)]e[39m at processTicksAndRejections (internal/process/task_queues.js:93:5)
[debug] e[35m[W3C (d1a96719)]e[39m at XCUITestDriver.proxyCommand (/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/lib/commands/proxy-helper.js:96:12)
[debug] e[35m[W3C (d1a96719)]e[39m at XCUITestDriver.postAcceptAlert (/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/lib/commands/alert.js:20:10)
[debug] e[35m[W3C (d1a96719)]e[39m at XCUITestDriver.mobileHandleAlert (/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/lib/commands/alert.js:34:14)
[debug] e[35m[W3C (d1a96719)]e[39m at XCUITestDriver.executeMobile (/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/lib/commands/execute.js:131:10)
[debug] e[35m[W3C (d1a96719)]e[39m at XCUITestDriver.execute (/usr/local/lib/node_modules/appium/node_modules/appium-ios-driver/lib/commands/execute.js:15:12)
[debug] e[35m[W3C (d1a96719)]e[39m at XCUITestDriver.execute (/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/lib/commands/execute.js:16:10)
e[35m[HTTP]e[39m e[37m<-- POST /wd/hub/session/d1a96719-2204-427a-ae6d-3d3a175b6b7e/execute/sync e[39me[31m500e[39m e[90m736 ms - 1701e[39m
e[35m[HTTP]e[39m e[90me[39m
org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: *** -[__NSArrayM insertObject:atIndex:]: object cannot be nil
Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:17:03’
System info: host: ‘C02WP0FUHTD8’, ip: ‘fe80:0:0:0:c69:e750:3089:42f9%en0’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.16’, java.version: ‘14.0.2’
Driver info: io.appium.java_client.ios.IOSDriver
Capabilities {app: /Users/kg036443/Documents/G…, automationName: XCuiTest, browserName: , clearSystemFiles: true, databaseEnabled: false, device: iPhone, deviceName: Office iphone, enablePerformanceLogging: true, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: false, newCommandTimeout: 20000, platform: MAC, platformName: iOS, platformVersion: 15.2, printPageSourceOnFindFailure: true, takesScreenshot: true, udid: 00008030-0009648C3690402E, useNewWDA: true, wdaLocalPort: 8200, webStorageEnabled: false}
Session ID: d1a96719-2204-427a-ae6d-3d3a175b6b7e
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.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
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.ios.IOSDriver.execute(IOSDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:489)
at saaas.api.ProvisionUsingAppStepDefinition.launch_the_authentication_app(ProvisionUsingAppStepDefinition.java:203)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at cucumber.runtime.Utils$1.call(Utils.java:26)
at cucumber.runtime.Timeout.timeout(Timeout.java:16)
at cucumber.runtime.Utils.invoke(Utils.java:20)
at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:48)
at cucumber.runner.PickleStepDefinitionMatch.runStep(PickleStepDefinitionMatch.java:50)
at cucumber.runner.TestStep.executeStep(TestStep.java:63)
at cucumber.runner.TestStep.run(TestStep.java:49)
at cucumber.runner.PickleStepTestStep.run(PickleStepTestStep.java:43)
at cucumber.runner.TestCase.run(TestCase.java:44)
at cucumber.runner.Runner.runPickle(Runner.java:40)
at cucumber.runtime.junit.PickleRunners$NoStepDescriptions.run(PickleRunners.java:146)
at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:68)
at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:23)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:73)
at cucumber.api.junit.Cucumber.runChild(Cucumber.java:124)
at cucumber.api.junit.Cucumber.runChild(Cucumber.java:65)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at cucumber.api.junit.Cucumber$1.evaluate(Cucumber.java:133)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:542)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:770)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:464)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)

1 Like

What have you tried? Tried simple tap by text “Allow” ?

driver.executeScript(“mobile: alert”, ImmutableMap.of(“action”, “accept”));

Earlier same code was working. After upgraded XCode 13.2 and both simulator and device getting this issue.

  1. try https://appiumpro.com/editions/31-automating-custom-alert-buttons-on-ios
  2. fail nr 1 -> switch to tap by text

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

This one also I tried getting same error, also navigated to the element and tried calling click() event, then also failed

I use simple tap by text with iOS alerts.

Hey @KUMARAVEL-kg @Aleksei

I am also seeing the same issue, After upgrading to XCode 13.2. IS there any work around for it?

It’s a bug in iOS. See Error on click on location permission dialog on iOS 15.0

once again. i just use search element by exact name and it works without problem with 15.1 and 15.2

@iOSXCUITFindBy(iOSNsPredicate = "type == 'XCUIElementTypeButton' AND visible == 1 AND 
 (name == 'Allow While Using App' OR name == 'Allow')")

I wasn’t able to click the element directly, I got this error:

# Ruby bindings
@driver.find_element(:xpath, "//XCUIElementTypeButton[@label='Ask App Not to Track']").click
# throws this error:
# An unknown server-side error occurred while processing the command. Original error: *** -[__NSArrayM insertObject:atIndex:]: object cannot be nil

My solution was to find the coordinates for the alert button I wanted to tap and then tap on that specific location. I already had much of this code written in my appium interface, but perhaps this will help you:

def get_middle_coordinates(locator)
    location = @driver.find_element(locator).location
    size = @driver.find_element(locator).size

    x = (size["width"] / 2) + location["x"]
    y = (size["height"] / 2) + location["y"]

    return { x: x, y: y }
end

def tap_by_coordinates(x, y)
    Appium::Core::TouchAction
        .new(@driver)
        .tap(x: x, y: y)
        .perform
end

accept_alert_locator = { xpath: "//XCUIElementTypeButton[@label='Ask App Not to Track']" }
middle_coordinates = get_middle_coordinates(accept_alert_locator)
tap_by_coordinates(x: middle_coordinates[:x], y: middle_coordinates[:y])

I have same issue, and I fixed it by that:
public void clickSystemNotification(MobileElement element) {
Actions action = new Actions(getDriver());
action.moveToElement(getDriver().findElement(By.id(“Allow”)));
action.click();
action.perform();
}

3 Likes

The iOS bug you mentioned has been fixed in Appium 1.22.1 and 2.0.0-beta. be sure you are running one of those versions and you should be fine. Also, learn from my mistake and dont use the Appium Desktop app. For whatever reason, it is running v 1.22.0 and has this bug present.
Hope this helps someone.

2 Likes

A big thank you to you @catsandcode it took me 2 days to reach out to the solution which is provided by you, it works.
My IOS developer has to create a new label “label=“okBTN”” to facilitate this–> This thing I additionally need to do to resolve this issue.

But anyway thanks a lot.

1 Like

Thanks for letting me know. I’m glad I was able to help someone. :grinning:

This will solve the issue. Thanks to @catsandcode

1 Like

Thanks dear. It’s real working.

1 Like

thanks a lot!
Helped with camera permission “OK” on iOS 15.1 iPhone 7
Just changed to appium 1.22.1!

1 Like

obrigado jovem, salvou aqui.

@catsandcode :- Thanks a lots , have never thought about upgrading appium . This worked and with 1.22.1 its working fine… Thanks again.

1 Like