Skip to content
Back to skills

Mobile Accessibility Test Ids

ASecurity

Use when adding or fixing stable UI-test locators and accessibility labels in a Kotlin Multiplatform or native mobile app - Compose testTag, testTagsAsResourceId, SwiftUI accessibilityIdentifier versus accessibilityLabel, contentDescription, Appium (UiAutomator2, XCUITest), Maestro or XCUITest not finding an element, Appium showing only XCUIElementTypeOther on Compose Multiplatform iOS, flaky XPath or text-based selectors, QA asking for test IDs, XCUITest performAccessibilityAudit, or Accessi...

  • 17 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 3, 2026
developmentgoswiftkotlinshellnodetestinggitapi

Works with

  • cli
  • api
  • mcp

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned December 4, 2026

npx -y skills add Kushpawan/kmp-mobile-skills --skill mobile-accessibility-test-ids --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Mobile Accessibility Test Ids?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Mobile Accessibility Test Ids
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/kushpawan-mobile-accessibility-test-ids/badge)](https://www.skillsdirectory.com/skills/kushpawan-mobile-accessibility-test-ids)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: mobile-accessibility-test-ids
description: Use when adding or fixing stable UI-test locators and accessibility labels in a Kotlin Multiplatform or native mobile app - Compose testTag, testTagsAsResourceId, SwiftUI accessibilityIdentifier versus accessibilityLabel, contentDescription, Appium (UiAutomator2, XCUITest), Maestro or XCUITest not finding an element, Appium showing only XCUIElementTypeOther on Compose Multiplatform iOS, flaky XPath or text-based selectors, QA asking for test IDs, XCUITest performAccessibilityAudit, or Accessibility Nutrition Labels readiness.
license: Apache-2.0
compatibility: Compose Multiplatform or Jetpack Compose on Android; Compose Multiplatform or SwiftUI on iOS. Inspecting the iOS accessibility tree needs macOS with Xcode; performAccessibilityAudit needs iOS 17+. Optional inspectors are the Maestro CLI (maestro mcp) and the Android CLI (android layout).
metadata:
  category: testing
  platforms: android, ios
---

# Mobile accessibility test IDs

Every interactive element carries two different things:

- a **locator**: a stable, never-translated ID that tests use. This is `Modifier.testTag` in Compose
  and `accessibilityIdentifier` in SwiftUI and UIKit.
- a **spoken label**: localised prose that TalkBack and VoiceOver read aloud. This is
  `contentDescription` in Compose and `accessibilityLabel` in SwiftUI and UIKit.

They are never the same string. IDs live in one namespaced object per screen, shared with the tests,
and they follow one naming scheme on both platforms.

## The id contract

| Where the id is read | What a Compose `testTag` becomes | Condition |
|---|---|---|
| Compose UI tests (`onNodeWithTag`) | the tag itself | none |
| Android accessibility tree: UiAutomator, Appium UiAutomator2, Maestro, `android layout` | `resource-id` | an ancestor sets `testTagsAsResourceId = true` (Android API, `androidMain`) |
| iOS accessibility tree (Compose Multiplatform): XCUITest, Appium XCUITest, Maestro | `accessibilityIdentifier` | documented by JetBrains; confirm per screen |
| SwiftUI / UIKit | `accessibilityIdentifier` set directly | none |

**Verify, don't assume.** JetBrains documents that `testTag` maps to the iOS
`accessibilityIdentifier` for XCTest
([Compose Multiplatform iOS accessibility](https://kotlinlang.org/docs/multiplatform/compose-ios-accessibility.html)).
Some Appium users still report Compose Multiplatform iOS screens that show only nested
`XCUIElementTypeOther` elements with no identifiers. Those reports are anecdotal and do not name
versions. Maestro 2.13.0 did see every `testTag` id on a Compose Multiplatform 1.13.0 iOS simulator
build in December 2026, so the mapping works; check each screen anyway, because a custom
`semantics` or interop view can still hide ids. Before you write a single locator for a screen, look
at the real tree of a real build:
Xcode Accessibility Inspector or `app.debugDescription` on iOS, Maestro MCP `inspect_screen` on
either platform, `android layout` (Android CLI) or `adb shell uiautomator dump` on Android.

## When to use

- Building or reviewing a screen that QA automation, end-to-end tests or Compose UI tests will drive.
- Appium, Maestro, UiAutomator or XCUITest cannot find a Compose or SwiftUI element.
- Selectors are flaky: XPath by position, matching on visible text, list rows by index.
- Someone put an ID into `contentDescription` or `accessibilityLabel` to make a test pass.
- Adding an XCUITest accessibility audit, or preparing to declare Accessibility Nutrition Labels.

## When not to use

- A full manual accessibility review (focus order, VoiceOver rotors, custom actions): see the
  external accessibility skills under Related skills. This skill covers ids, labels, the automated
  XCUITest audit and Nutrition Label readiness.
- Writing Compose UI tests: `compose-multiplatform-ui-testing`. Writing Maestro flows:
  `kmp-maestro-e2e`. Screenshot tests: `kmp-screenshot-testing`. ViewModel unit tests:
  `kmp-testing-patterns`.
- Appium installation, driver setup, WebDriverAgent or session start failures: the official
  [appium/skills](https://github.com/appium/skills) (`setup-*`, `appium-troubleshooting`).

## Step 0 - Read the project first

1. **Find the existing ID convention.** Search for `testTag(`, `TestTags`, `accessibilityIdentifier(`
   and `AccessibilityID`. If the project already has a scheme (for example dot notation such as
   `login.email`), keep it. Mixing schemes breaks shared test helpers.
2. **Find where IDs live.** Look for `<Screen>TestTags` objects next to the screens, and a Swift
   `enum` namespace in the app or in a package.
3. **Find the test tools.** Appium suites (look for `capabilities`, `UiAutomator2`, `XCUITest`),
   `.maestro/` flows, `*UITests` targets, and Compose `runComposeUiTest` / `createComposeRule` tests.
   The tool decides how an ID must be exposed (see Workflow step 4). Also note which inspectors you
   can run here: Xcode (macOS only), the Maestro CLI (`maestro mcp` exposes `inspect_screen`), the
   Android CLI (`android layout`), `adb`, Appium Inspector.
4. **Find the Android host root.** The `setContent {}` call in the `Activity`, plus every
   `Dialog`, `ModalBottomSheet` or `Popup`. That is where `testTagsAsResourceId` belongs.
5. **Check the UI layer.** Compose Multiplatform on both platforms, Compose on Android with SwiftUI
   on iOS, or fully native.

## Workflow

1. **Pick the elements to tag.** Tag every element a test acts on or waits for:
   - buttons, links and tab items;
   - text fields, toggles and pickers;
   - list-row tap targets;
   - dialog and sheet actions (confirm **and** cancel);
   - the screen root, so a test can assert "we are on screen X";
   - error banners, empty states, retry buttons, loading indicators.

   Do **not** tag decorative images, dividers, spacers or layout-only containers. Over-tagging makes
   page sources noisy and invites accidental duplicates.

2. **Name the IDs: `<screen>_<element>_<role>`**, in snake_case and English-only. They are never shown
   to users and never translated.

   | Role suffix | Example |
   |---|---|
   | `_screen` | `notes_list_screen` |
   | `_button` | `notes_list_add_button` |
   | `_input` | `note_editor_title_input` |
   | `_toggle`, `_link`, `_tab` | `settings_sync_toggle`, `settings_privacy_link` |
   | `_row_<stableId>` | `notes_list_row_42` |
   | `_dialog`, `_dialog_confirm_button`, `_dialog_cancel_button` | `notes_list_delete_dialog_confirm_button` |
   | `_error`, `_empty_state`, `_loading` | `notes_list_empty_state` |

   - An ID is unique on its screen. Give global surfaces (an app-wide error dialog) a global name
     such as `app_error_dialog`.
   - **Dynamic rows use a stable model ID, never the list index.** An insert, a sort or a new page
     shifts indices, and the test then taps the wrong row without any error.
   - Use the **same string on Android and iOS**. A Compose Multiplatform `testTag` becomes the iOS
     `accessibilityIdentifier`, so one Maestro or Appium flow can drive both platforms.

3. **Declare the IDs once per screen.**

   ```kotlin
   // commonMain, next to NotesListScreen.kt
   object NotesListTestTags {
       const val SCREEN = "notes_list_screen"
       const val ADD_BUTTON = "notes_list_add_button"
       const val EMPTY_STATE = "notes_list_empty_state"
       const val DELETE_DIALOG = "notes_list_delete_dialog"
       const val DELETE_DIALOG_CONFIRM_BUTTON = "notes_list_delete_dialog_confirm_button"
       const val DELETE_DIALOG_CANCEL_BUTTON = "notes_list_delete_dialog_cancel_button"
       private const val ROW_PREFIX = "notes_list_row_"

       fun row(noteId: String): String = ROW_PREFIX + noteId
   }
   ```

   ```kotlin
   @Composable
   fun NotesList(state: NotesUiState, onAction: (NotesAction) -> Unit, modifier: Modifier = Modifier) {
       Box(modifier.fillMaxSize().testTag(NotesListTestTags.SCREEN)) {
           LazyColumn {
               items(state.notes, key = { it.id }) { note ->          // stable key AND stable tag
                   NoteRow(
                       note = note,
                       onClick = { onAction(NotesAction.Open(note.id)) },
                       // the tag goes on the node that receives the click, not on an inner Text
                       modifier = Modifier.testTag(NotesListTestTags.row(note.id)),
                   )
               }
           }
           FloatingActionButton(
               onClick = { onAction(NotesAction.Add) },
               modifier = Modifier.align(Alignment.BottomEnd).testTag(NotesListTestTags.ADD_BUTTON),
           ) {
               // contentDescription is the spoken label: localised prose, not the ID
               Icon(painterResource(Res.drawable.ic_add), contentDescription = stringResource(Res.string.add_note))
           }
       }
   }
   ```

   SwiftUI screens get a namespaced `enum`. Put it in a package (`public`) or in a file that belongs
   to both the app target and the UI-test target, so tests use the same constants:

   ```swift
   public enum AccessibilityID {
       public enum NotesList {
           public static let screen = "notes_list_screen"
           public static let addButton = "notes_list_add_button"
           public static func row(_ noteID: String) -> String { "notes_list_row_\(noteID)" }
       }
   }

   extension View {
       func accessibilityID(_ id: String) -> some View { accessibilityIdentifier(id) }

       /// A card or row whose wrapper carries the ID while its children stay individually queryable.
       func accessibilityContainerID(_ id: String) -> some View {
           accessibilityElement(children: .contain).accessibilityIdentifier(id)
       }
   }

   // Call sites: never an inline string literal
   Button("Add note", action: onAdd).accessibilityID(AccessibilityID.NotesList.addButton)
   ForEach(notes) { note in
       NoteRow(note: note).accessibilityContainerID(AccessibilityID.NotesList.row(note.id))
   }
   ```

   Never inline a raw ID string at a call site. The constant is what keeps a rename safe across the
   app and its tests.

4. **Expose the IDs to the tools.**

   - **Compose tests** (`runComposeUiTest`, `createComposeRule`) see `testTag` directly through
     `onNodeWithTag(...)`. Nothing else is needed.
   - **Android UiAutomator, Appium (UiAutomator2) and Maestro** read the accessibility tree, not the
     Compose tree. A `testTag` appears there as a `resource-id` only when an ancestor sets
     `testTagsAsResourceId = true`. Set it once, high in the tree, at the Activity root:

     ```kotlin
     // androidMain - host Activity
     setContent {
         Box(Modifier.fillMaxSize().semantics { testTagsAsResourceId = true }) {
             App()
         }
     }
     ```

     `testTagsAsResourceId` is an Android API of Jetpack Compose UI. Use it from `androidMain`. If your
     Compose version reports it as experimental, add `@OptIn(ExperimentalComposeUiApi::class)`.
     Content in a `Dialog`, `ModalBottomSheet` or `Popup` is hosted in a separate window, and the
     Activity root's flag may not reach it. When that content is declared in `commonMain`, add a
     one-line `expect`/`actual` modifier: the Android `actual` sets the flag, the iOS `actual` returns
     `this`. Apply it at the dialog's content root.

     ```kotlin
     // commonMain
     expect fun Modifier.exposeTestTagsAsResourceIds(): Modifier
     // androidMain
     actual fun Modifier.exposeTestTagsAsResourceIds(): Modifier = semantics { testTagsAsResourceId = true }
     // iosMain
     actual fun Modifier.exposeTestTagsAsResourceIds(): Modifier = this
     ```

   - **iOS with Compose Multiplatform**: the official docs state that `testTag` maps to the native
     `accessibilityIdentifier`, which is what XCUITest, Appium's XCUITest driver and Maestro query.
     Before Compose Multiplatform 1.8.0, the iOS accessibility tree synced only while an accessibility
     service ran. On those versions, test builds set
     `accessibilitySyncOptions = AccessibilitySyncOptions.Always(debugLogger = null)` in
     `ComposeUIViewController(configure = { ... })`. From 1.8.0 the option is gone: the tree loads on
     demand. Confirm each ID in a real build: Accessibility Inspector (Xcode > Open Developer Tool >
     Accessibility Inspector; look at "Identifier"), Maestro MCP `inspect_screen` on the simulator,
     or `app.debugDescription` in a UI test. If a tool shows only `XCUIElementTypeOther` nodes with no
     identifier, record the Compose Multiplatform version and the tool, and compare with
     Accessibility Inspector.
     Do not fall back to XPath, coordinates or label matching without telling the user.
   - **SwiftUI and UIKit** expose `accessibilityIdentifier` directly. If you put an identifier on a
     container without `.accessibilityElement(children: .contain)`, SwiftUI may apply it to every child
     element. Use the container helper above, then confirm in Accessibility Inspector.

5. **Add spoken labels separately, only where needed.** Material and SwiftUI controls with visible
   text already have a label. Add `contentDescription` / `accessibilityLabel` to icon-only buttons,
   images that carry meaning, and rows that need a summary. Never put an ID in a label. A screen reader
   would read "notes underscore list underscore add underscore button" aloud, and every copy change
   would then break a test.

6. **Find elements in tests by ID.** The per-tool syntax and pitfalls are in
   [references/finding-elements.md](references/finding-elements.md): Appium UiAutomator2 (which adds a
   package prefix to `id` locators by default), Appium XCUITest, Maestro, XCUITest, UiAutomator and
   Compose tests.
   *Done when* each new ID is located once by the real tool, on each platform that ships the screen.

7. **Audit what the ids cannot show.** On iOS, add or extend an XCUITest that navigates to the screen
   and calls `try app.performAccessibilityAudit()` (iOS 17+). It works on Compose Multiplatform and
   SwiftUI screens. If the team plans to declare Accessibility Nutrition Labels (voluntary now;
   Apple says they will be required over time), run the readiness checklist. Both are in
   [references/accessibility-audits.md](references/accessibility-audits.md).
   *Done when* the audit test passes on each new screen state, or each remaining issue is fixed or
   listed with a reason.

## Quick reference

| Concept | Compose (Android and CMP) | SwiftUI / UIKit |
|---|---|---|
| Locator (tests) | `Modifier.testTag("id")` | `.accessibilityIdentifier("id")` |
| Spoken label | `contentDescription` / `semantics { contentDescription = ... }` | `.accessibilityLabel(...)` |
| Hint | `semantics { onClick(label = ...) }` (action label) | `.accessibilityHint(...)` |
| Expose to UiAutomator / Appium / Maestro | `semantics { testTagsAsResourceId = true }` on a root (`androidMain`) | automatic |
| Seen on iOS as | `accessibilityIdentifier` (Compose Multiplatform) | `accessibilityIdentifier` |
| ID home | `<Screen>TestTags` object in `commonMain` | `enum AccessibilityID { enum <Screen> { ... } }` |
| Composite rows | tag the clickable row root; `useUnmergedTree = true` to reach children in Compose tests | `.accessibilityElement(children: .contain)` + identifier |
| Inspect the real tree | `android layout`, `adb shell uiautomator dump`, Maestro `inspect_screen` (`rid` = resource-id) | Accessibility Inspector, Maestro `inspect_screen`, `app.debugDescription` |
| Automated audit | (not covered here) | `try app.performAccessibilityAudit()` in an XCUITest (iOS 17+) |

## Verify

- **Compile**: the module builds on both platforms (`kmp-build-check`, or the module's compile tasks).
- **Android**: run `android layout --pretty` (Android CLI), `adb shell uiautomator dump`, Maestro
  MCP `inspect_screen` (the `rid` key), or Appium Inspector. Each tagged element shows `resource-id`
  equal to the tag. If there is no `resource-id`, the `testTagsAsResourceId` ancestor is missing for
  that window.
- **iOS**: in Accessibility Inspector, Maestro MCP `inspect_screen` on the simulator, or Appium
  Inspector (the `name` attribute), each element shows its identifier. A tree of bare
  `XCUIElementTypeOther` nodes with no identifiers is a **FAIL** for that screen, not a reason to
  switch to XPath.
- **Audit**: the XCUITest with `performAccessibilityAudit()` passes for each new screen.
- **Tests**: the new IDs are found by the project's real suite (Maestro flow, Appium test, XCUITest or
  Compose test).

Report each item as PASS, FAIL or NOT RUN with the reason. For example: "iOS inspection NOT RUN: no
macOS host". Name the tool used for each inspection. Never report an ID as working on a platform where
it was not inspected or exercised.

## Common mistakes

| Mistake | Why it bites | Fix |
|---|---|---|
| ID placed in `contentDescription` / `accessibilityLabel` | Screen readers read it aloud; translations and copy edits break tests | Locator in `testTag` / `accessibilityIdentifier`; prose in the label |
| No `testTagsAsResourceId` ancestor | UiAutomator, Appium and Maestro on Android see no `resource-id` | Set it once at the Activity root, and again in dialog or sheet windows |
| `semantics { testTagsAsResourceId = true }` in `commonMain` | It is an Android API, so the common compile fails | `androidMain` host root, or an `expect`/`actual` modifier |
| Appium `id` locator for a Compose tag | UiAutomator2 adds `<package>:id/`, so the bare tag never matches | Turn off ID autocompletion, or use a `UiSelector().resourceId(...)` (see reference) |
| Appium `accessibility id` on Android for a `testTag` | On Android it matches `content-desc`, not the tag | Use `resource-id` on Android; `accessibility id` works on iOS |
| Row ID built from the list index | Reordering or paging taps the wrong row silently | `row(note.id)` from a stable model ID |
| Tag on an inner `Text` instead of the clickable node | The test taps a node that has no click action | Tag the node that has the click handler |
| Identifier on a SwiftUI stack without `.contain` | Children may all inherit the same identifier | `.accessibilityElement(children: .contain)` first |
| Inline ID strings at call sites | Renames drift between the app and the tests | Constants in `TestTags` / `AccessibilityID` |
| Different schemes on Android and iOS | One cross-platform flow cannot drive both | One `<screen>_<element>_<role>` string per element |
| ID parameters added to every design-system component | API noise; IDs end up inside components | Tag at the call site; add a sub-element ID parameter only for a documented QA need |
| Assuming Appium sees a Compose Multiplatform `testTag` on iOS because the docs say so | Some teams report trees of bare `XCUIElementTypeOther`; locators then fail only on iOS | Inspect each screen in a real build first; report what the tool shows |
| Using `a11y` (or `txt`) from `inspect_screen` as a Maestro `id:` | `a11y` is the label or content description, not the id | `id:` matches `rid` on Android and the identifier on iOS |
| Treating a passing `performAccessibilityAudit()` as Nutrition Label support | The audit checks one screen state, automatically; labels need every common task done with the feature | Run the readiness checklist with the assistive technology turned on |

## Review checklist

1. Every new interactive element, screen root, dialog action, error, empty state and retry has an ID.
2. IDs come from the screen's `TestTags` object or the `AccessibilityID` enum. No inline literals.
3. IDs follow `<screen>_<element>_<role>` (or the project's existing scheme) and are identical across
   platforms.
4. Dynamic rows use a stable model ID. Lazy lists also use `key = { it.id }`.
5. Locator and spoken label are separate, and labels are localised.
6. Android: one `testTagsAsResourceId` root per window (activity, dialogs, sheets), set from
   `androidMain`.
7. SwiftUI: composite rows use `.accessibilityElement(children: .contain)`.
8. Each new ID has been seen in an inspector, or found by a test, on each platform.
9. iOS screens have an XCUITest accessibility audit, or a stated reason why not.

## Related skills

- `compose-multiplatform-ui-testing`: Compose UI tests with `onNodeWithTag` on every target.
- `kmp-maestro-e2e`: Maestro flows that drive both platforms through these ids.
- `kmp-screenshot-testing`: screenshot tests of the same screens.
- `kmp-testing-patterns`: unit tests for the state behind the screen.
- `kmp-build-check`: confirm the tagged screens compile on both platforms.
- `compose-multiplatform-screen`: the screen shape that owns a `<Screen>TestTags` object.
- `compose-design-system-component`: design-system components, tagged at the call site.
- [appium/skills](https://github.com/appium/skills): official Appium setup and troubleshooting
  skills (Apache-2.0, linked): driver setup, WebDriverAgent, locator failures.
- [dadederk/iOS-Accessibility-Agent-Skill](https://github.com/dadederk/iOS-Accessibility-Agent-Skill): VoiceOver, Dynamic Type and accessible SwiftUI/UIKit.
- [skydoves/android-testing-skills](https://github.com/skydoves/android-testing-skills): Compose UI testing, UiAutomator and Espresso skills.
- [chrisbanes/skills](https://github.com/chrisbanes/skills): Compose skills, including UI testing patterns.
- [AvdLee/Swift-Testing-Agent-Skill](https://github.com/AvdLee/Swift-Testing-Agent-Skill): Swift Testing.

Files in this skill

  • SKILL.md15.9 KB
  • references/finding-elements.md6.4 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.