driver.acceptAlert() is tapping Don't Allow

driver.acceptAlert() and ‘appium:autoAcceptAlerts’: true are clicking on Don’t Allow instead of Allow Once.
Screenshot 2024-09-11 at 14.52.42

This issue is also related to other alerts - clicking on the wrong buttons.
appium-xcuitest-driver version is 7.26.2
appium version 2.11.3
iOS Sim 18.0
Xcode RC 16.0

You can tune accept dismiss alert text here
Settings - Appium XCUITest DriveracceptAlertButtonSelector + dismissAlertButtonSelector.

Also you can change above setting right before you expecting this alert and restore default after (as idea) …

@Aleksei, thanks for your response, but it’s not working. I put this setting into capabilities and it’s clicking ‘Don’t Allow’ anyway.
‘appium:settings[acceptAlertButtonSelector]’: ‘//XCUIElementTypeButton[@name=“Allow Once”]’

Also tried this to update the setting during the script execution - didn’t work.
await driver.updateSettings({ acceptAlertButtonSelector: ‘//XCUIElementTypeButton[@name=“Allow Once”]’ });
or
await driver.updateSettings({ ‘appium:acceptAlertButtonSelector’: ‘//XCUIElementTypeButton[@name=“Allow Once”]’ });

OK, found the right way to do that. The selector must be only a class chain selector. So this worked:
await driver.updateSettings({ acceptAlertButtonSelector: '**/XCUIElementTypeButton[name == “Allow Once”]' });

And to restore to default settings:
await driver.reloadSession();

Exactly! As said in doc…

1 Like