iOS Alerts
Alert capabilities allow you to configure an auto accept/dismiss of iOS popup alerts. This comes in handy when you wish to avoid having tests fail because alerts and popups prevented the driver from recognizing and interacting with elements in the app.
info
Supported for iOS 9 and above.
Name | Possible Values | Notes |
---|---|---|
autoAcceptAlerts | true / false Default: false | OK/Allow/Accept The alert popup will be accepted and disappear immediately on any element related consecutive operation which is executed after the popup appeared |
autoDismissAlerts | true / false Default: false | Dismiss/Don't allow/Close/Cancel/Not now/...Later The alert popup will be dismissed and disappeared immediately on any element related consecutive operation which is executed after the popup appearing |
info
Replace "autoAcceptAlerts" with "autoDismissAlerts" to dismiss alerts
Java
public void test() throws MalformedURLException {
IOSDriver<IOSElement> driver = null;
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability("app", app);
dc.setCapability("autoAcceptAlerts", true);
driver = new IOSDriver<>(new URL(<server>), dc);
// clicking on this button will cause a popup alert with "Don't allow" and "OK" buttons to appear
driver.findElement(By.xpath("//*[@XCElementType='XCUIElementTypeButton']")).click();
// clicking on a button behind the popup alert will cause the popup to disappear
driver.findElement(By.xpath("//*[@XCElementType='XCUIElementTypeButton'][3]")).click();
}
Python
def test():
dc = {}
self.dc['platformName'] = 'ios'
self.dc['app'] = app
self.dc['autoAcceptAlerts'] = True
self.driver = webdriver.Remote(<server>, self.dc)
# // clicking on this button will cause a popup alert with "Don't allow" and "OK" buttons to appear
self.driver.find_element_by_xpath("xpath=//*[@XCElementType='XCUIElementTypeButton']")
# // clicking on a button behind the popup alert will cause the popup to disappear
self.driver.find_element_by_xpath("xpath=//*[@XCElementType='XCUIElementTypeButton[3]']")
C Sharp
public void test() throws MalformedURLException {
IOSDriver<IOSElement> driver = null;
DesiredCapabilities dc = new DesiredCapabilities();
dc.SetCapability("app", app);
dc.SetCapability("autoAcceptAlerts", true);
driver = new IOSDriver<>(new URL(<server>), dc);
// clicking on this button will cause a popup alert with "Don't allow" and "OK" buttons to appear
driver.FindElement(By.xpath("//*[@XCElementType='XCUIElementTypeButton']")).Click();
// clicking on a button behind the popup alert will cause the popup to disappear
driver.FindElement(By.xpath("//*[@XCElementType='XCUIElementTypeButton'][3]")).Click();
}
Ruby
def test_ios_app
desired_caps = {
caps: {
app: 'app',
autoAcceptAlerts: true,
},
appium_lib: {
server_url: '<server>',
}
}
@driver = Appium::Driver.new(desired_caps, true).start_driver
# clicking on this button will cause a popup alert with "Don't allow" and "OK" buttons to appear
@driver.find_element(:xpath, "//*[@XCElementType='XCUIElementTypeButton']").click
# clicking on a button behind the popup alert will cause the popup to disappear
@driver.find_element(:xpath, "//*[@XCElementType='XCUIElementTypeButton'][3]").click
end