UI Automation Element Locating for Android and iOS Using WEditor and Appium
This guide explains how to set up and use WEditor for Android and tidevice/Appium for iOS to locate UI elements efficiently, covering prerequisite tools, installation commands, step‑by‑step connection procedures, error handling, and best‑practice strategies for reliable mobile UI automation.
To perform UI automation testing, accurate element locating is essential. This article outlines practical methods for Android and iOS, summarizing tools, setup steps, and key insights gained from real‑world automation projects.
Android Element Locating
Prerequisites: adb, Python 3, an Android device with developer options enabled.
Tool: WEditor (cross‑platform).
Installation:
pip install weditorConnect the Android device (enable USB debugging) and verify with:
adb devicesStart WEditor:
python -m weditorIn the WEditor UI, select Android, enter the device ID obtained from adb devices , and click connect . Install the prompted app on the device.
Open the target app, click Dump Hierarchy to capture the UI tree; refresh to capture new pages as needed.
If the error atx-agent recover failed occurs, run:
pip install --upgrade --pre uiautomator2iOS Element Locating
Prerequisites: Python 3, an iPhone with WebDriverAgent installed.
Tools: tidevice, Appium 1.21.0+
Installation:
pip install tideviceCheck installed apps and obtain the bundle ID:
tidevice applistList connected iOS devices to get the UDID:
tidevice listStart WebDriverAgent:
tidevice -u <UDID> wdaproxy -B <WDA package> -p 8200Launch Appium server (version 1.20.2 or later) and create a new session using a JSON representation, for example:
{
"deviceName": "xxxx",
"bundleId": "xxxxx",
"platformVersion": "14.4",
"udid": "000080xxxxxxxxxxxE",
"webDriverAgentUrl": "http://localhost:8200",
"platformName": "IOS",
"xcodeOrgId": "xxxxxx",
"automationName": "XCUITest",
"usePrebuiltWDA": true,
"useXctestrunFile": false,
"skipLogCapture": true
}After the session starts, you can begin capturing elements.
Key Takeaways
Simplicity: Prefer straightforward locating strategies:
Android: id > text > img > ocr > xpath iOS: name > text > img > ocr > xpath Web/H5: name > id > text > selectorNetwork Latency: Use framework methods like finds with timeout and interval scanning, and element_is_existed to return True or False based on element presence.
Fuzzy Matching: When text varies across versions, apply fuzzy matching on partial text to improve robustness.
Summary
Element locating is the foundation of UI automation; without reliable locators, actions cannot be performed.
The choice of locating strategy impacts test efficiency, stability, and coverage.
Tools like WEditor and Appium Inspector assist in discovering locator attributes but are not the solution themselves.
Understanding widget characteristics, implementation details, and layout principles is essential for effective element locating.
转转QA
In the era of knowledge sharing, discover 转转QA from a new perspective.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.