๐ฏ Elements & Locators
Every UI interaction in a Ghost skill needs to find an element. This page covers the locator model.
The locator chain
Section titled โThe locator chainโGhostโs tap_element and wait_for_element primitives use a fallback chain, tried in order:
id:โ Android resource-id or iOS accessibility-id. Most precise. Changes between app builds.desc:โ content-desc (Android) or accessibility label (iOS). Most stable across app versions.text:โ visible text. Locale-dependent. Weak.xpath:โ full xpath expression. Escape hatch for complex hierarchies (limited support in v2).
First match wins. If no match found โ StepFailedError with hint: "consider wait_for_element before this step".
steps: - {action: tap_element, desc: "Send button"} # try desc first - {action: tap_element, id: "com.whatsapp:id/send"} # id-based, brittle to app updates - {action: tap_element, text: "Save"} # text-based, locale-fragileBest practice: prefer desc: โ most stable across app versions + locales. Use id: when desc is missing. Use text: only when the text is a known-stable UI landmark (โPostโ, โSendโ, โCancelโ).
Getting locators
Section titled โGetting locatorsโTwo ways to discover the right locator:
Live inspection (recommended)
Section titled โLive inspection (recommended)โWhile the app is on the target screen:
adb -s <serial> shell uiautomator dump --compressed /sdcard/ui.xmladb -s <serial> pull /sdcard/ui.xml /tmp/ui.xmlgrep -oE '(content-desc|resource-id|text)="[^"]+"' /tmp/ui.xml | sort -uLook for a unique attribute on the element you want to tap. Content-desc is best.
Ghost inspector (via Skill Creator)
Section titled โGhost inspector (via Skill Creator)โghost skill mine <skill> --explore # planned (v1.7); not in v1.6.0BFS walks the app, records every screen, extracts stable locators. Faster than manual inspection.
Coord blind-tap (for known-stable landmarks)
Section titled โCoord blind-tap (for known-stable landmarks)โSome elements have NO stable a11y attributes โ TikTokโs bottom-nav icons are content-desc="Profile" (stable, use desc:), but the display-name area at the top of the profile page (used to open the account-switcher) has no reliable attribute. In those cases, use empirically-verified coordinates:
- {action: tap, x: 972, y: 2214} # TT Profile bottom-nav, 1080x2400 devices- {action: sleep, duration_s: 2}When to use blind-tap:
- Known-stable landmark whose position doesnโt shift across app versions
- No content-desc / resource-id / text is available
- Video-app screens where
uiautomatorcanโt reach idle (TT/IG/YT autoplay pages)
When NOT to blind-tap: modals, dynamic content, small target areas, screens where coords could shift with an app update. Always prefer a11y locators when they exist.
Document your coord choices in the skillโs SOFT.md so future adapt passes know what to preserve.
Element filtering by attribute
Section titled โElement filtering by attributeโCurrently supported: id, desc, text. Combined filters (find element matching multiple attrs) not yet in v2 โ use xpath: for complex cases:
- {action: tap_element, xpath: "//android.widget.Button[@content-desc='Send' and @clickable='true']"}Note: xpath support in v2 is minimal โ id/desc/text covers 95% of cases. Extend via custom_python if you need more.
Locator patterns per app class
Section titled โLocator patterns per app classโNative Android apps (Chrome, Gmail, Instagram):
- Content-desc is usually populated and stable
- Resource-id changes on major app updates
- Text works but is locale-dependent
React Native / Flutter apps (many indie apps):
- Content-desc often missing (framework doesnโt emit it by default)
- Resource-id often auto-generated hashes โ unstable across builds
- Text or coord may be the only viable option โ use
screen_hash:validator to detect drift
Web-view apps (banking, some social):
- Locators are actually browser-side โ use
url_contains:validators open_url+type_textinto form fields- iframe elements especially hard to hit โ often needs
custom_pythonwith WebView-JS injection
Video-autoplay apps (TikTok, Instagram, YouTube):
uiautomator dumpfails to reach idle- Use blind-tap for bottom-nav / known landmarks
- Dump AFTER navigating to a static page (profile, settings) โ thatโs when a11y is reliable
_fast_dumpin the engine handles Portal fallback automatically
Related
Section titled โRelatedโ- Creating Skills โ full author flow
- Skill Schema v2 Reference โ tap_element + wait_for_element specs
- Execution Engine โ the fast_dump gotcha, Layer 1-4 popup handling