---
title: A Note on Mobile Locators | TestingBot
description: 'Everything so far was about web pages: a DOM, CSS, XPath over HTML,
  and roles computed by the browser. Native iOS and Android apps have none of the
  first…'
source_url:
  html: https://testingbot.com/resources/courses/locator-strategies/a-note-on-mobile-locators
  md: https://testingbot.com/resources/courses/locator-strategies/a-note-on-mobile-locators.md
---

Course

[Selenium Locators and Locator Strategies](https://testingbot.com/resources/courses/locator-strategies)

Chapter 10 of 12

1. [1 Selenium Locators: Strategies That Survive Change](https://testingbot.com/resources/courses/locator-strategies)
2. [2 Why Tests Break on Locators](https://testingbot.com/resources/courses/locator-strategies/why-locators-break)
3. [3 Inspect the DOM and Test Selectors in DevTools](https://testingbot.com/resources/courses/locator-strategies/inspect-and-test-selectors-in-devtools)
4. [4 CSS Selectors for Test Automation](https://testingbot.com/resources/courses/locator-strategies/css-selectors)
5. [5 XPath in Selenium: Text, Axes and When to Use It](https://testingbot.com/resources/courses/locator-strategies/xpath-in-selenium)
6. [6 Role-Based, Label and Relative Locators](https://testingbot.com/resources/courses/locator-strategies/role-based-and-relative-locators)
7. [7 A Test ID Contract With Your Developers](https://testingbot.com/resources/courses/locator-strategies/a-test-id-contract)
8. [8 Shadow DOM and iframes](https://testingbot.com/resources/courses/locator-strategies/shadow-dom-and-iframes)
9. [9 Lists, Tables and Dynamic Content](https://testingbot.com/resources/courses/locator-strategies/lists-tables-and-dynamic-content)
10. [10 A Note on Mobile Locators](https://testingbot.com/resources/courses/locator-strategies/a-note-on-mobile-locators)
11. [11 A Locator Review Checklist](https://testingbot.com/resources/courses/locator-strategies/locator-review-checklist)
12. [12 Locator Strategies Knowledge Check](https://testingbot.com/resources/courses/locator-strategies/knowledge-check)

[Exit course](https://testingbot.com/resources/courses)

 Chapter 10 of 12 Intermediate 4 min read 1 quick check Updated Nov 2026 

# A Note on Mobile Locators
On this page
1. [No DOM, no CSS](https://testingbot.com#no-dom-no-css)
2. [The mobile equivalents](https://testingbot.com#the-mobile-equivalents)
3. [Finding locators on a device](https://testingbot.com#finding-locators-on-a-device)
4. [Summary](https://testingbot.com#summary)

Everything so far was about web pages: a DOM, CSS, XPath over HTML, and roles computed by the browser. Native iOS and Android apps have none of the first three, and many web habits transfer badly. This chapter is a short map of what changes. The [Appium with WebdriverIO course](https://testingbot.com/resources/courses/appium-webdriverio/locate-elements) covers mobile locators hands-on.

## No DOM, no CSS[#](https://testingbot.com#no-dom-no-css)

A native screen is a tree of platform UI elements (`android.widget.Button`, `XCUIElementTypeButton`), which Appium exposes as XML through the platform's accessibility and automation layers. CSS selectors do not apply at all. XPath works, because Appium can serialise the tree to XML, but that serialisation is the expensive part: on every XPath lookup the driver dumps the whole screen and then evaluates the expression, which on a large screen is far slower than a native query.

Mobile _browsers_ are different: a web page in Safari on an iPhone or Chrome on Android has a normal DOM, and everything in chapters 3 to 8 applies unchanged. The same is true inside the webview context of a hybrid app.

## The mobile equivalents[#](https://testingbot.com#the-mobile-equivalents)

| Web habit | Native equivalent | Notes |
| --- | --- | --- |
| `data-testid` | **accessibility id** (`content-desc` on Android, `accessibilityIdentifier` on iOS) | Cross-platform, fast, stable; the first choice |
| Hand-written `id` | Android `resource-id` | Usually stable across releases |
| Role and accessible name | the element type plus its label or text | Copy changes and translations break it, just as on the web |
| CSS for structure | `-android uiautomator` selectors, `-ios predicate string`, `-ios class chain` | Evaluated natively on the device, much faster than XPath |
| XPath | XPath over the XML tree | Last resort: slow, and absolute paths break on any layout change |

The test id contract from chapter 6 carries over directly: on mobile it is a contract about accessibility identifiers. Agree on a naming scheme with the iOS and Android developers, use the same value on both platforms, and the same test code finds the element on both. Because accessibility ids feed into what assistive technology reads on Android, check with the developers which property they set, so that a test hook does not end up announced to screen reader users.

## Finding locators on a device[#](https://testingbot.com#finding-locators-on-a-device)

DevTools does not exist for native apps. The equivalent is an inspector that shows the element tree of the live app: Appium Inspector, or the inspector built into TestingBot's [App Live](https://testingbot.com/support/app-live/appium-inspector), which you open from the DevTools icon during a live session, without any local setup. The same rules apply as in chapter 2: read the attributes around the element before copying, and rewrite generated XPath into an accessibility id or a native selector.

Our blog post on [mobile locators for automated testing](https://testingbot.com/blog/mobile-locators-for-appium) compares the strategies with examples, and the [mobile app testing course](https://testingbot.com/resources/courses/mobile-app-testing) covers choosing between Appium, Maestro, Espresso and XCUITest.

An Appium suite for an Android app uses XPath copied from the inspector everywhere, and each lookup takes over a second on large screens. What is the best first step?

 Convert the XPath expressions to CSS selectors Increase the implicit wait Shorten the XPath expressions to start with `//` Ask for accessibility ids on the elements the tests use and locate by accessibility id

CSS does not exist in a native context. A longer wait makes slow lookups slower. Shorter XPath is less brittle but still requires dumping the whole screen to XML on every lookup. Accessibility ids are resolved natively and work on both platforms.

## Summary[#](https://testingbot.com#summary)

- Native apps have no DOM and no CSS; XPath works but is slow and brittle.
- Accessibility ids are the mobile test id: agree on them with developers, the same value on iOS and Android.
- Mobile browsers and webviews are web pages, and the rest of this course applies to them.

[Previous · Chapter 9 Lists, Tables and Dynamic Content](https://testingbot.com/resources/courses/locator-strategies/lists-tables-and-dynamic-content) [Next · Chapter 11 A Locator Review Checklist](https://testingbot.com/resources/courses/locator-strategies/locator-review-checklist)

On this page

1. [No DOM, no CSS](https://testingbot.com#no-dom-no-css)
2. [The mobile equivalents](https://testingbot.com#the-mobile-equivalents)
3. [Finding locators on a device](https://testingbot.com#finding-locators-on-a-device)
4. [Summary](https://testingbot.com#summary)

Certification

Earn the free, resume-worthy TestingBot Locator Strategies Certification for this course.

[How it works](https://testingbot.com/resources/courses/locator-strategies/certification)
