Selecting buttons in iOS alert is not working on real device

Hey!
I am testing native iOS app on iOS 13/14. I have alert with 4 buttons, and I want to tap one of it.

At first, I have function to get titles of all buttons in alert:

private List getIOSAlertButtonsLabels() {
WebDriverWait wait = new WebDriverWait(driver, iOSAlertTimeout);
wait.until(ExpectedConditions.alertIsPresent());
HashMap<String, String> args = new HashMap<>();
args.put(“action”, “getButtons”);
return (List) ((IOSDriver) driver).executeScript(“mobile: alert”, args);
}

Another function is for performing tap on button by its index:

public void tapIOSAlertItem(int index) {
HashMap<String, String> args = new HashMap<>();
args.put(“action”, “accept”);
args.put(“buttonLabel”, getIOSAlertButtonsLabels().get(index));
Sleep.sleep(3000);
((IOSDriver) driver).executeScript(“mobile: alert”, args);
}

On my local machine on simulators all is working correct and fast.
But while running or real iPhone click on button is not working (btw, this button has title “Поменять язык интерфейса” on Russian language):

2020-10-26 10:31:59:672 - [HTTP] {“script”:“mobile: alert”,“args”:[{“action”:“accept”,“buttonLabel”:“Поменять язык интерфейса”}]}
2020-10-26 10:31:59:673 - [debug] [MJSONWP (94fc0bc4)] Calling AppiumDriver.execute() with args: [“mobile: alert”,[{“action”:“accept”,“buttonLabel”:“Поменять язык интерфейса”}],“94fc0bc4-a136-4767-a7e9-18d2350c3fe6”]
2020-10-26 10:31:59:673 - [debug] [XCUITest] Executing command ‘execute’
2020-10-26 10:31:59:674 - [debug] [WD Proxy] Matched ‘/alert/accept’ to command name ‘postAcceptAlert’
2020-10-26 10:31:59:674 - [debug] [WD Proxy] Proxying [POST /alert/accept] to [POST http://127.0.0.1:8402/session/E2983CE8-8E06-4FA8-A7D7-0458F348E8B2/alert/accept] with body: {“name”:“Поменять язык интерфейса”}
2020-10-26 10:31:59:864 - [WD Proxy] Got response with status 400: {“value”:{“error”:“invalid element state”,“message”:“Error Domain=com.facebook.WebDriverAgent Code=1 “Failed to find button with label Поменять язык интерфейса for alert: Sheet” UserInfo={NSLocalizedDescription=Failed to find button with label Поменять язык интерфейса for alert: Sheet}”,“traceback”:"(\n\t0 WebDriverAgentLib 0x0000000108e6da64 +[FBAlertViewCommands handleAlertAcceptCommand:] + 592\n\t1 WebDriverAgentLib 0x0000000108e2e018 -[FBRoute_TargetAction mountRequest:intoResponse:] + 208\n\t2 WebDriverAgentLib 0x0000000108e14d90 __37-[FBWebServer registerRouteHandlers:]_block_invoke + 496\n\t3 RoutingHTTPServer 0x0000000108f71ec8 -[RoutingHTTPServer handleRoute:withRequest:response:] + 144\n\t4 RoutingHTTPServer 0x0000000108f726a8 __72-[RoutingHTTPServer routeMethod:withPath:parameters:request:connection:]_block_invoke + 44\n\t5 libdispatch.dylib 0x00000001a1599fd8 D174E751-B542-3…
2020-10-26 10:31:59:864 - [debug] [W3C] Matched W3C error code ‘invalid element state’ to InvalidElementStateError
2020-10-26 10:31:59:864 - [debug] [MJSONWP (94fc0bc4)] Encountered internal error running command: InvalidElementStateError: Error Domain=com.facebook.WebDriverAgent Code=1 “Failed to find button with label Поменять язык интерфейса for alert: Sheet” UserInfo={NSLocalizedDescription=Failed to find button with label Поменять язык интерфейса for alert: Sheet}

Is there any way to make this working or there is there options to work with iOS alerts?

Thank you.

-> iOS 14's alert dialog boxes can't be dismissed

Yes, I sow that topic.
But, I think, I have a different case, as:

  1. I also tried on iOS 13 device
  2. Buttons order is not important, as needed button is selected by its label (that was already successfully found)
  3. All is working on simulators.

Why not just tap using some predicate? This is alert which has some alert class name and some button classes. Also did you try look at pagesource on this screen? Is button with label you mention exists?