I’m facing an issue where I can’t allow the location permission on the simulator. I’ve tried the following method, but it only works on iOS 18:
I’m running tests on iOS Simulator using Appium, and my app triggers the standard location permission: “Allow Once” / “Allow While Using App” / “Don’t Allow”.
I’ve already tried setting these desired capabilities:
"autoAcceptAlerts": true
"autoDismissAlerts": true
But the alert is not dismissed automatically. I also tried locating the alert buttons manually using XPath or accessibility ID, but the elements are not visible or interactable through Appium.
Is there a reliable way to auto-dismiss or bypass this alert during automation on iOS simulators?
I’m currently using: Appium 2.19.0, iOS 18.4 Simulator.
Any suggestions or best practices would be appreciated.
Thank you for your reply. I tried to recreate your code in Python, but I’m getting an error: Failed to set acceptAlertButtonSelector: 'WebDriver' object has no attribute 'set_settings'. Do you know why this is happening and how to fix it?
def accept_ios_location_alert():
success = False
try:
appiumlib = BuiltIn().get_library_instance('AppiumLibrary')
driver = appiumlib._current_application()
print(f"{driver}")
except Exception as e:
print(f"❌ Failed: {e}")
return False
try:
selector = "**/XCUIElementTypeButton['name == \"Allow While Using App\" OR name == \"Allow\"']"
driver.set_settings({
"acceptAlertButtonSelector": selector
})
print(f"✅ Setting 'acceptAlertButtonSelector' success di-set: {selector}")
except Exception as e:
print(f"❌ Filed set acceptAlertButtonSelector: {e}")
return False
time.sleep(3)
try:
alert = driver.switch_to.alert
alert_text = alert.text
print(f"⚠️ Alert is appears: {alert_text}")
except:
print("✅ Alert success dismiss.")
success = True
return success