Pop-up Interaction Failing Due to Incorrect XPath Detection

We’re facing an intermittent issue where the tracking permission pop-up fails to appear on some iOS devices during automation runs, while it works fine on others — despite identical test capabilities being used.

"autoAcceptAlerts": false,
"autoGrantPermissions": false

Devices impacted: iPhone 11/16

Hey @ian-partridge,

The failure in pop-up interaction during automated testing is due to incorrect XPath detection caused by a change in the UI element hierarchy.

The automation script, when attempting to locate the “Ask App Not To Track” system alert, mistakenly identifies the element as “splash-screen-overlay” instead. This misidentification leads to failed interactions, as the script cannot click on the correct button.

:mag: Issue Breakdown:

  • Incorrect Element Detection:
    The automation tool identifies the overlay element instead of the actionable “Ask App Not To Track” button.

  • Expected XPath:

//XCUIElementTypeButton[@name="Ask App Not To Track"] | //XCUIElementTypeButton[@name="Ask App Not to Track"]

  • Detected XPath:

Detected element: "splash-screen-overlay"

:iphone: Device-Specific Behavior:

  • The issue does not occur on iPhone 11 running iOS 18.
  • The issue appears on iPhone 16.

Attempted Fix:

  • Developers enabled the setting settings[respectSystemAlerts] = true within the automation framework.

  • This configuration allows the framework to properly recognize and respect system-generated alerts like permission requests or tracking prompts.

Resolution:

  • Enabling settings[respectSystemAlerts] to true, ensures that system alerts are prioritized and handled accurately by the automation engine.

  • Once this setting was applied, the automation script was able to correctly detect and interact with the “Ask App Not To Track” button, resolving the issue.

:jigsaw: Code Implementation (LambdaTest - iOS, Appium Java)

The following Java code shows how settings[respectSystemAlerts] = true was configured within the LT:Options capability, ensuring system alerts like “Ask App Not To Track” are correctly detected and interacted with during automated testing:

ltOptions.put("settings[respectSystemAlerts]", true);

This configuration was added inside the @BeforeMethod setup block. Below is the full test code snippet:

import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
import java.util.HashMap;
import io.appium.java_client.AppiumBy;
import io.appium.java_client.ios.IOSDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.ITestContext;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class expedia {
    private RemoteWebDriver driver;
    private String Status = "Passed";
    private String deviceName = "iPhone 11"; // Use "iPhone 16" to test issue

    @BeforeMethod
    public void setup(Method m, ITestContext ctx) throws MalformedURLException {
        String username = "";
        String authkey = "";
        String hub = "@mobile-hub.lambdatest.com/wd/hub";

        DesiredCapabilities caps = new DesiredCapabilities();
        HashMap<String, Object> ltOptions = new HashMap<>();
        ltOptions.put("platformName", "ios");
        ltOptions.put("deviceName", deviceName);
        ltOptions.put("platformVersion", "18");
        ltOptions.put("build", "you build name here");
        ltOptions.put("app", "<"your app id goes here">");
        ltOptions.put("isRealMobile", true);
        ltOptions.put("w3c", true);
        ltOptions.put("autoAcceptAlerts", false);
        ltOptions.put("autoGrantPermissions", false);
        ltOptions.put("acceptInsecureCerts", true);
        ltOptions.put("appiumVersion", "2.4.1");
        ltOptions.put("allowInvisibleElements", true);
        ltOptions.put("settings[respectSystemAlerts]", true); // ✅ Key fix
        caps.setCapability("LT:Options", ltOptions);

        driver = new IOSDriver(new URL("https://" + username + ":" + authkey + hub), caps);
    }

    @Test
    public void basicTest() {
        try {
            Thread.sleep(5000);
            try {
                WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(15));
                wait.until(ExpectedConditions.invisibilityOfElementLocated(AppiumBy.xpath("//*[@name='splash-screen-overlay']")));
                System.out.println("Splash screen is gone.");
            } catch (Exception e) {
                System.out.println("Splash screen did not disappear: " + e.getMessage());
            }

            Thread.sleep(5000);
            // Ask App Not To Track Handling (Robust Locators)
            try {
                WebElement askNotToTrackButton;
                if (deviceName.equals("iPhone 16")) {
                    askNotToTrackButton = driver.findElement(AppiumBy.xpath(
                        "//XCUIElementTypeButton[@name='Ask App Not To Track'] | //XCUIElementTypeButton[@name='Ask App Not to Track']"));
                } else {
                    askNotToTrackButton = driver.findElement(AppiumBy.iOSNsPredicateString(
                        "type == 'XCUIElementTypeButton' AND (name == 'Ask App Not To Track' OR name == 'Ask App Not to Track')"));
                }
                askNotToTrackButton.click();
                System.out.println("Clicked on Ask App Not To Track button successfully.");
            } catch (Exception e) {
                System.out.println("Ask App Not To Track button not found or click failed: " + e.getMessage());
            }

            Thread.sleep(5000);
        } catch (InterruptedException e) {
            System.out.println("Thread interrupted: " + e.getMessage());
        }
    }

    @AfterMethod
    public void tearDown() {
        try {
            driver.executeScript("lambda-status=" + Status);
        } catch (Exception e) {
            System.out.println("Error setting LambdaTest status: " + e.getMessage());
        }
        try {
            driver.quit();
        } catch (Exception e) {
            System.out.println("Error quitting the driver: " + e.getMessage());
        }
    }
}

Hope this solutions was helpful , if there is any query or you find your self still stuck, feel free to reach out to us.

Happy Testing :grinning: !!