Skip to content

XCUITest error messages: what each one means and how to fix it

An XCUITest failure is one line: the step that failed and the reason. Every message on this page is quoted from Xcode 26.4’s own frameworks (XCUIAutomation, XCTestCore, XCTHarness and IDEFoundation), read with strings. Words in angle brackets are what Xcode fills in.

Xcode builds the line from two parts. The first is Failed to and the step, with its first letter lowercased: Tap "Login" Button becomes Failed to tap "Login" Button. The second, after the colon, is the reason. This line is from a test on iOS 26, posted to Apple’s forums:

Failed to tap "myTabItem" Button: No matches found for Elements matching predicate '"myTabItem" IN identifiers' from input

Search this page for the part after the colon.

Finding an element

No matches found for <query> from input <input>

The query found nothing in the accessibility tree at the moment the step ran. Xcode 26.4 also words it as No matches found for first query match sequence: <query>, given input <input>, and older logs say Failed to get matching snapshot before it.

The usual causes:

  • The screen hasn’t appeared yet when the line runs.
  • The identifier is on a different view than the one you query. In the forum post above, the identifier sat on the Label inside .tabItem, and the tab bar button didn’t carry it.
  • The query names the wrong type: a SwiftUI view with an onTapGesture is often not a Button in the tree.

Wait for the element, then print the tree the test saw when it still fails:

let pay = app.buttons["pay_button"]guard pay.waitForExistence(timeout: 10) else {    print(app.debugDescription)    XCTFail("pay_button never appeared")    return}pay.tap()

app.debugDescription lists every element with its type, identifier and label. Query by the type and identifier it shows. For a tab, query the tab bar: app.tabBars.buttons["Library"].

A Mobster check selects by id, label, role and value from the same tree and evaluates its accessibility-tree assertions together against one read (Checks).

Find single matching element. Multiple matching elements found for <query>.

The query matched two or more elements, and the step needed exactly one. query.element, and a subscript like app.buttons["Delete"] when you act on it, both require a unique match.

Give each control its own identifier:

ForEach(items) { item in    Button("Delete") { delete(item) }        .accessibilityIdentifier("delete_\(item.id)")}

When several matches are expected, pick one on purpose: app.buttons.matching(identifier: "Delete").element(boundBy: 0). firstMatch also stops the error, because it returns the first match without checking for others. Apple’s documentation says to use it only when one element can match.

A Mobster value assertion fails as “ambiguous” when two or more shown elements match, for the same reason.

Tapping, typing and scrolling

Not hittable: <element>

The element exists, but XCUITest can’t find a point on screen where a tap would reach it. Apple’s documentation says isHittable is false when the element doesn’t exist, is offscreen, or is covered by another element. Related lines are Failed to compute hit point for <element>: <error> and Unable to find hit point for <element>.

Common covers are the keyboard, a toast, a sheet sliding in, and a loading overlay. Wait for the cover to go, then for the element to become hittable. Both waits arrived in Xcode 16.3:

XCTAssertTrue(app.otherElements["loading_overlay"].waitForNonExistence(timeout: 10))XCTAssertTrue(save.wait(for: \.isHittable, toEqual: true, timeout: 5))save.tap()

To dismiss the keyboard first, tap a non-interactive area or the keyboard’s own Return or Done key. A coordinate tap, save.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap(), skips the hit test. Use it last: it taps whatever is on top.

Failed to scroll to visible (by AX action) <element>, error: <error>

Before it taps an offscreen element, XCUITest asks the app to scroll it into view through accessibility. This error says the scroll didn’t work. It is common with custom scroll containers and with content that scrolls by gesture only.

Scroll yourself, with a limit:

let row = app.cells["settings_privacy"]var swipes = 0while !row.isHittable && swipes < 8 {    app.tables.firstMatch.swipeUp()    swipes += 1}XCTAssertTrue(row.isHittable, "settings_privacy is still offscreen after 8 swipes")row.tap()

A Mobster check counts only elements on screen, so content scrolled out of view isn’t shown. A coding agent scrolls with swipe and until first (Checks).

Neither element nor any descendant has keyboard focus. Event dispatch snapshot: <snapshot>

typeText ran on an element that doesn’t hold keyboard focus. Apple’s documentation for typeText(_:) says the element or one of its descendants must have focus, or the call raises this error.

Tap the field, wait for the keyboard, then type into the field itself, not its label or container:

let email = app.textFields["email_field"]email.tap()XCTAssertTrue(app.keyboards.firstMatch.waitForExistence(timeout: 5))email.typeText("sam@example.com")

When the tap lands but the keyboard never shows on a simulator, check whether a hardware keyboard is connected in the simulator’s I/O menu.

The type_text tool in Mobster refuses to type until it has seen a keyboard on screen (MCP server).

Timing

Timed out while evaluating UI query.

XCUITest asked the app for a snapshot of its accessibility tree and didn’t get one in time. On Apple’s forums it shows as Failed to get matching snapshots: Timed out while evaluating UI query., beside Unable to perform work on main run loop, process main thread busy for 2.0s - recommend retry by client. Xcode 26.4 still has a related line: Application main thread did not become responsive within timeout of <seconds>.

The app’s main thread is busy, or the tree is very large. Look for:

  • work on the main thread during the step: decoding, image processing or a synchronous network call;
  • a query over the whole app that walks thousands of cells, such as app.tables.cells.allElementsBoundByIndex.

Query from a container and stop at the first match:

let feed = app.collectionViews["feed"]let firstPost = feed.cells.firstMatchXCTAssertTrue(firstPost.waitForExistence(timeout: 10))

Then profile the screen with Instruments’ Time Profiler. A longer timeout hides a main thread that your users wait on too. How to fix flaky XCUITests covers waits and animations in depth.

The app under test

Application <bundle id> is not running

The test acted on an app that isn’t running: it was never launched, it crashed, or terminate() ended it. A variant reads Application for <bundle id> is not running.

Launch it before the first query, and check its state when you share one app across tests:

let app = XCUIApplication()if app.state != .runningForeground {    app.launch()}

launch() terminates a running instance first, so call it when you want a clean start. When the app was running a moment before, it probably crashed: the result bundle has the crash report.

A Mobster check that ends with another app in front fails as app_not_running, and one whose app crashed fails as app_crashed, whatever its assertions say (Checks).

Application for <bundle id> is not foreground and does not allow background interaction.

Your app went to the background mid-test. A link opened Safari, a share sheet handed off to another app, or a system app came to the front. A sibling line says Application for <bundle id> is suspended.

Bring it back and wait for the state:

app.activate()XCTAssertTrue(app.wait(for: .runningForeground, timeout: 10))

To act on a system alert while your app is in front, query SpringBoard:

let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")let alert = springboard.alerts.firstMatch

Failed to activate application '<bundle id>' (current state: <state>)

activate() or launch() couldn’t bring the app to the foreground. On Apple’s forums it shows with current state: Running Background. An Apple engineer suggested the latest Xcode and turning off the debugger for the Test action: Product › Scheme › Edit Scheme › Test › Info › Debug executable.

Also check that nothing on screen holds the foreground: a passcode prompt, an alert from another app, or a locked iPhone. Add an interruption handler for alerts you expect:

addUIInterruptionMonitor(withDescription: "Notifications") { alert in    let allow = alert.buttons["Allow"]    guard allow.exists else { return false }    allow.tap()    return true}

The handler runs at the next interaction with the app, not by itself.

Lost connection to the application (pid <pid>).

The app’s process ended or became unreachable while a step waited on it. CI logs show it as Failed to get matching snapshot: Lost connection to the application (pid 7805). The usual cause is a crash. Out-of-memory kills during long suites are the next suspect.

Open the .xcresult bundle and read the crash log first. When there is none, read the device or simulator log around the failure for a jetsam event. Retrying hides it.

On a simulator, a Mobster check that crashes keeps the crash report, the symbolicated stack and the log 10 seconds either side (Testing).

Targeted element <element> is no longer valid after interruption handling.

Apple’s message explains it: this happens with UI that auto-dismisses when it loses first-responder status, which may occur as part of interruption handling. A permission alert appeared, a handler dismissed it, and the element you held went away with the focus.

Query the element again after the interruption instead of reusing the old reference. Better, prevent the alert. On a simulator, grant the permission before the test:

xcrun simctl privacy booted grant photos com.example.yourapp

In the test, app.resetAuthorizationStatus(for: .photos) resets one permission so you can test the alert on purpose.

Unknown application: '<bundle id>'

XCUIApplication(bundleIdentifier:) names an app that isn’t installed on the destination. Check the bundle identifier and what is installed:

xcrun simctl listapps booted | grep CFBundleIdentifierxcrun devicectl device info apps --device <UDID>

The test runner and the destination

The test runner timed out while preparing to run tests.

The UI test runner never got ready. Its siblings are The test runner hung before establishing connection. and The test runner exited with code <code> while preparing to run tests. On CI the cause is usually a simulator that is still booting, or a busy machine. On an iPhone, check that it is unlocked, trusts the Mac and has Developer Mode on.

Boot the simulator and wait for it before you test, and give xcodebuild time to find the destination:

xcrun simctl bootstatus <UDID> -bxcodebuild test -scheme YourApp \  -destination 'platform=iOS Simulator,name=iPhone 17 Pro' \  -destination-timeout 120

The test runner exited with code <code> before finishing running tests.

The full message in Xcode 26.4 gives the fix: “This may be due to your code calling ‘exit’, consider adding a symbolic breakpoint on ‘exit’ to debug.” A crash in test code, an exit() or fatalError() in app code reached from a test, or a precondition in a helper ends the runner.

Add a symbolic breakpoint on exit in Xcode’s breakpoint navigator, then run the one failing test with the debugger:

xcodebuild test -scheme YourApp -only-testing:YourAppUITests/OnboardingTests/testSkip \  -destination 'platform=iOS Simulator,name=iPhone 17 Pro'

Early unexpected exit, operation never finished bootstrapping - no restart will be attempted

xcodebuild gave up because the runner exited before its first test. The underlying error in the same line often reads Test runner exited before starting test execution. A forum report from CI on physical iPhones said the error repeated until the device restarted, and returned days later.

Open the session log the message points to: it holds the real failure. Then restart the iPhone. When it keeps coming back, install the app and runner once per device instead of on every run. Test an iOS app on a real iPhone walks through the device setup.

Device is not configured for UI testing - use of XCUIApplication is not supported.

The message continues: “This can happen when XCUIApplication is used in a unit test bundle instead of a UI test bundle.” A unit test bundle can’t drive your app through XCUIApplication.

Add a target from the UI Testing Bundle template, set its target to be tested to your app, and move every test that uses XCUIApplication into it. Keep unit tests in the unit test bundle.

Unable to find a destination matching the provided destination specifier:

xcodebuild found no simulator or device that matches every key in -destination. The name must match exactly, the OS must be a runtime you have installed, and a device must be connected and ready. List what xcodebuild sees for your scheme, and what simulators exist:

xcodebuild -showdestinations -scheme YourAppxcrun simctl list devices available

Copy a destination from that list, or pin one by its identifier:

xcodebuild test -scheme YourApp -destination 'platform=iOS Simulator,id=<UDID>'

The message ends with the specifier it tried and the destinations it found, under Available destinations for the "<scheme>" scheme: and Ineligible destinations for the "<scheme>" scheme:. An ineligible destination says why.

What a Mobster check does differently

A Mobster check is a YAML file of steps and declared expectations. Mobster evaluates its accessibility-tree assertions together against one read. It stops waiting when matching reads satisfy those assertions, or uses the last read at the timeout (5 s by default). Other checks and execution evidence also affect the verdict. By default, a failed check is retried once with its configured reset, and a check that passes on the retry is marked flaky. An action whose outcome is unknown stops the check and is never retried. mobster test --repeat 5 gives each check a pass rate (Testing).

It still fails when your app crashes, hangs or never shows the screen. It names which, with the frame.

Get Mobster for Mac to run checks on your simulators and your own iPhone: free (AI runs on a supported AI plan, an API key or a model on your Mac).

Questions

  • Where do I see the full XCUITest error?

    In the test report, open the failed test and expand its activity. The failure line names the step ("Failed to tap") and the reason. xcodebuild prints the same line, and the .xcresult bundle keeps it with a screenshot of the failure.

  • Why does a query work in the debugger but fail in the test?

    The debugger reads the tree after the screen has settled. The test reads it the moment the line runs. Wait for the element with waitForExistence(timeout:) before you tap it, and print app.debugDescription at the failure to see the tree the test saw.

  • Does firstMatch fix "Multiple matching elements found"?

    It stops the error, because firstMatch returns the first match without checking for others. Apple's docs say to use it only when one element can match. A unique accessibility identifier fixes the cause.

Sources