Automating Custom Alert Buttons on iOS

April 22, 2026 · 8 min read · Mobile Testing

HeadSpin Platform
Automated & amp; manual testing made easygoing through data science insight.
Differentiating capableness:
  • All-inclusive end-to-end automation of QA process
  • Relative analysis of app execution against match
  • Continuous monitoring of app performance using synthetic data for higher availability of apps
  • Easy-to-use developer friendly platform
cloudtest go
Affordable Existent Device Testing for Emerging Teams
cloudtest go
Low-cost Real Device Testing for Digital Enterprises
cloudtest go
The Ultimate Solution for a Powerful Blend of Functional & amp; Performance Testing!
cyol
TEM
New
Centralized peregrine test execution in cloud
cyol
Enhance Your Accessibility Testing With HeadSpin
cyol
Automate camera-based examination

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

retail

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

Automating Custom Alert Buttons on iOSAutomating Custom Alert Buttons on iOS

Automating Custom Alert Buttons on iOS

Published on
August 22, 2018
Updated on
Published on
May 31, 2022
Updated on
 by 
 Jonathan LippsJonathan Lipps
Jonathan Lipps

iOS alert treatment has often been a testy subject (pun! pun!). Luckily, with the current XCUITest driver used by Appium, we can connect directly to Apple-approved method for accepting or dismissing an alerting, or even getting its schoolbook. Appium provides approach to this behavior via the standard suite of WebDriver alert commands, for example:

driver.switchTo () .alert () .alert () driver.switchTo () .alert () .dismiss () driver.switchTo () .alert () .getText ()

Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script.

Check out:

Unfortunately, the WebDriver spec is not quite as flexible as mobile apps when it comes to the pattern of alerts. The WebDriver spec was found around web browser alerts, which can contain at most two action buttons. Mobile apps can make native alerting which carry 3 or even more button! So, what do you do when you need to automatize the action associated with a push which is not & quot; OK & quot; or & quot; Cancel & quot;?

For example, I & # x27; ve added a feature toThe App& # x27; s list view which enables you to tap a third awake button when you choose a cloud character:

Cloud Selection

When you tap this 3rd button, another alert appears with some extra information about the cloud type:

non-convective cloud

But backwards to the maiden alert. We want to click the & quot; Learn more about Cirrostratus & quot; brisk option. In this suit, we could probably use the fact that we know the name of the button to find it in the UI hierarchy. But what if we didn & # x27; t know the text of the button, only that we wanted to tap the third push, whatever it contains? Luckily, Appium has a special dictation for handling alerts on iOS that you can use for this purpose:mobile: alarm.

Also check:

This command does allow you to accept and dismiss alert as usual, but that & # x27; s not very interesting. We & # x27; re going to look at two new use cases: getting a list of the available push labels and tapping an alert action via its label. These characteristic together will aid resolve the problem under consideration. Let & # x27; s take a look at an example:


HashMapargs = new HashMap < > (); args.put (`` action '', `` getButtons ''); Listbuttons = (List) driver.executeScript (`` mobile: alert '', args);

Following the pattern of the other mobile: method, we use executeScript with a special command and parameters to get the list of push labels. Once we feature this list, we can do whatever we need with it. Today, we & # x27; ll only try to extract the first label which isn & # x27; t one of the defaults (taking care to shed an exception if there is no such label):

String buttonLabel = null; for (String button: buttons) {if (button.equals (`` OK '') || button.equals (`` Cancel '')) {continue;} buttonLabel = button;} if (buttonLabel == zippo) {throw new Error (`` Did not get a third rattling push as we were expecting '');}

At this point, we hold the value of the button we want to press in thebuttonLabelvarying. We can again usemobile: alert to target this specific button, using a differentaction parameter than before (with a value of& quot; accept & quot;), and bring the new parameterbuttonLabelto let Appium know which push we want it to tap for us:

args.put (`` activity '', `` accept ''); args.put (`` buttonLabel '', buttonLabel); driver.executeScript (`` mobile: alarm '', args);

That & # x27; s all there is to it! Usingmobile: alarumwe have approach to the full set of lively activity that can be displayed in an iOS app. See the full example below to see it work in the setting of my test app or check out the codificationon GitHub!

import io.appium.java_client.MobileBy; import io.appium.java_client.MobileElement; import io.appium.java_client.ios.IOSDriver; import java.io.IOException; signification java.net.URL; importation java.util.HashMap; import java.util.List; import org.junit.After; import org.junit.Before; meaning org.junit.Test; import org.openqa.selenium.By; importee org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; public grade Edition031_iOS_Alerts {private String APP = `` https: //github.com/cloudgrey-io/the-app/releases/download/v1.6.1/TheApp-v1.6.1.app.zip ''; individual IOSDriver driver; private WebDriverWait hold; private By listView = MobileBy.AccessibilityId (`` List Demo ''); private By cloud = MobileBy.AccessibilityId (`` Cirrostratus ''); @ Before public nothingness apparatus () throws IOException {DesiredCapabilities caps = new DesiredCapabilities (); caps.setCapability (`` platformName '', `` iOS ''); caps.setCapability (`` platformVersion '', `` 11.4 ''); caps.setCapability (`` deviceName '', `` iPhone 6 ''); caps.setCapability (`` app '', APP); driver = new IOSDriver(new URL (`` http: //localhost:4723/wd/hub ''), caps); wait = new WebDriverWait (driver, 10);} @ After public void tearDown () {try {driver.quit ();} catch (Exception ign) {}} @ Test public void testCustomAlertButtons () {wait.until (ExpectedConditions.presenceOfElementLocated (listView)) .click (); WebElement cloudItem = wait.until (ExpectedConditions.presenceOfElementLocated (cloud)); cloudItem.click (); wait.until (ExpectedConditions.alertIsPresent ()); HashMapargs = new HashMap < > (); args.put (`` action '', `` getButtons ''); Listbuttons = (List) driver.executeScript (`` mobile: alert '', args); // find the schoolbook of the button which is n't 'OK ' or 'Cancel' String buttonLabel = null; for (String push: buttons) {if (button.equals (`` OK '') || button.equals (`` Cancel '')) {continue;} buttonLabel = push;} if (buttonLabel == null) {throw new Error (`` Did not get a tertiary alert button as we be expecting '');} args.put (`` action '', `` accept ''); args.put (`` buttonLabel '', buttonLabel); driver.executeScript (`` mobile: alert '', args); wait.until (ExpectedConditions.alertIsPresent ()); // here we could verify that the new push press worked, but for now just publish it out String alertText = driver.switchTo () .alert () .getText (); System.out.println (alertText);}}
Author & # x27; s Profile

Jonathan Lipps

LinkedIn
Author & # x27; s Profile

Piali Mazumdar

Lead, Content Marketing, HeadSpin Inc.

Piali is a dynamical and results-driven Content Marketing Specialist with 8+ years of experience in crafting absorb tale and market collateral across various industries. She excels in collaborating with cross-functional teams to develop advanced content strategies and deliver compelling, authentic, and impactful substance that resonates with prey audiences and enhances make authenticity.

LinkedIn

Automating Custom Alert Buttons on iOS

4 Parts

regression intelligence blog
-

Regression Intelligence practical guide for advanced user (Part 3)

Coming Soon
Regression Intelligence practical guide for advanced users
-

Regression Intelligence hard-nosed guide for advanced users (Part 4)

Coming Soon

Discover how HeadSpin can empower your business with superior testing capacity

Our Platform enables you to:
accelerate time-to-market
Accelerate time-to-market, acquire a free-enterprise edge
faster development cycles
Boost developer/QA productivity with faster development round
automated buil-over-build regression testing
Automate build-over-build fixation testing for ordered results
gain better visibility into functional & performance issues
Gain better visibleness into functional and performance issues
reduce mean time
Reduce mean time to identify/resolve during tryout, QA, and production
evaluate audio, video & qoe
Evaluate audio, video, and contented lineament of experience (QoE) effortlessly
The trusted choice for global enterprises
Adobe
Hargreaves Lansdown
Truecaller
Crazylabs
Nedbank
Numeracle
Veryon
Close

Discover how HeadSpin can empower your business with superior prove capabilities

Our Platform enable you to:
accelerate time-to-market
Accelerate time-to-market, gaining a competitive edge
faster development cycles
Boost developer/QA productivity with faster development cycles
automated buil-over-build regression testing
Automate build-over-build fixation testing for reproducible results
gain better visibility into functional & performance issues
Gain better visibility into functional and performance issues
reduce mean time
Reduce meanspirited time to identify/resolve during test, QA, and product
evaluate audio, video & qoe
Evaluate audio, video, and content quality of experience (QoE) effortlessly
The trusted choice for world enterprises
Close

Discover how HeadSpin can empower your concern with superior testing capabilities

Our Platform enables you to:
accelerate time-to-market
Accelerate time-to-market, gaining a competitory edge
faster development cycles
Boost developer/QA productiveness with faster development round
automated buil-over-build regression testing
Automate build-over-build regression testing for consistent results
gain better visibility into functional & performance issues
Gain better visibility into functional and performance number
reduce mean time
Reduce mean clip to identify/resolve during test, QA, and product
evaluate audio, video & qoe
Evaluate sound, video, and content quality of experience (QoE) effortlessly
The trusted selection for global enterprises
Close

Connet Now

Wipro LogoVMLYR Logo
Close
Book a Meeting
Products
footer down arrow
Solutions
footer down arrow
Industries
footer down arrow
Features
footer down arrow
Support
footer down arrow
Resource Center
footer down arrow
Why Choose HeadSpin?
footer down arrow
Copyright © 2026 HeadSpin, Inc. All Rights Reserved.

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free