Unable to click on Allow once in iOS precise location pop up

I am trying to click on the ‘Allow once’ button in the location pop-up in iOS but for some reason, I am unable to interact with it.

I tried with both xpaths and accept alert still the result was same. Xapth I used //*[contains(@label, 'Allow Once')] and driver.switchTo().alert().accept();

try →

// Java
            final String iosLocator = "**/XCUIElementTypeButton[`name == \"Allow Once\"`]";
            driver.setSetting("acceptAlertButtonSelector", iosLocator);
            try {
                driver.switchTo().alert().accept();
            } catch (Exception ignored) {
            }

// or 

        // prepare args
        HashMap args = new HashMap<>();
        args.put("action", "accept");
        args.put("buttonLabel","Allow Once");

        // prepare command
        String cmd = "mobile: alert";

        // execute
        try {
            driver.executeScript(cmd, args);
        } catch (Exception ignored) {
        }
3 Likes

It worked, thank you