UI Automation Control Technology - Minimalist Practical Guide
Hello everyone, my name is Cline.
Recently, I have received many private messages from classmates, all asking the same question: **How can we implement App crawlers or simple automated tests on Android quickly? ** We don’t want to read hundreds of pages of framework documents, nor do we want to mess with bottomless custom controller classes. Today’s content will only focus on 3 mainstream tools to help you understand scene comparisons in 5 minutes. Douyin practice can be run in 30 minutes after copying. The whole process does not involve any mathematical formulas and is completely a guide for engineering implementation.
Core Objectives
- According to the three dimensions of "lightweight/cross-platform/game", select the most suitable tool within 3 seconds
- Master the two core precise positioning methods of "UI tree positioning" and "image recognition"
- Copy and run a synchronized version of Douyin likes + comments script with safe avoidance strategy
- Remember the three basic anti-crawling points for mobile automation
1. Tool comparison and quick start with the core
Don’t rush to install it yet, just look at the scenario cheat sheet below and you’ll be able to find the tool that best suits your current needs at a glance.
For the vast majority of quick tasks on the pure Android side, uiautomator2 is the lowest-cost and fastest-getting-started option. This article will use it as the main demonstration.
1.1 Get started with uiautomator2 first (use it in actual combat)
uiautomator2 is a pure Python library that calls Android's official uiautomator framework at the bottom. It has high performance, simple interface, and is very friendly to crawlers and automated testing.
Minimalist installation & initialization
In just two steps, you can let your computer control your Android phone:
5 lines of core operation demonstration (taking Taobao as an example)
The following code shows the most commonly used operation process: connect the device → launch the app → locate the element → tap to enter → slide and search.
1.2 Airtest quick start (blind filling game, special scenes)
When interface elements cannot be parsed through the UI tree (such as games, H5 embedded pages, special custom controls), Airtest's native image recognition capabilities are the best choice. At the same time, it also provides the Poco module to parse the UI tree, a two-pronged approach.
Minimalist installation
5-line core demo: image + UI dual positioning
2. Core pit avoidance + stable positioning solution
2.1 UI element positioning: select from high to low according to stability
The mobile interface changes frequently, and the positioning strategy should try to rely on those attributes that are not easy to change. The priority is as follows:
-
resourceId (most stable)
-
contentDescription/description (accessibility label)
-
textMatches (fuzzy text matching)
-
Image recognition (last choice)
- When taking screenshots, only capture small images that have no dynamic text and only contain core icons.
- Be sure to set
thresholdParameter (recommended 0.7~0.9, the higher the value, the stricter the matching, but it may not be found)
To sum up a formula: resourceId comes first, description text comes second, and image recognition comes last.
2.2 Basic anti-crawling gesture: simulate "real person operation"
The platform's risk control system will detect whether the operation is too mechanical, so we need to carve some "human touch" into the script.
-
Replace hard waiting with conditional waiting and add a little random delay
-
Randomization of sliding distance, duration, and position
-
Click the position to add a random offset
These three points are the basic defense lines for anti-climbing on the mobile terminal. The cost is extremely low, but the effectiveness is significant.
3. Practical combat: the synchronized version of Douyin with safe avoidance of pitfalls to automatically like + comment
⚠️ Important Reminder This script is only for personal learning and communication. Please do not use it for large-scale brushing or batch crawling. Otherwise, Douyin’s risk control mechanism may be triggered, resulting in traffic restrictions, bans, and even account closures.
3.1 Preparation
- Turn on "USB debugging" on your Android phone (the first connection must be authorized through USB; you can switch to WiFi debugging later)
- Open Douyin on your mobile phone and stay on the homepage of the recommended stream or the homepage of a certain video.
- Use the element positioning tool (Newbies strongly recommend the Poco Inspector that comes with Airtest IDE. Students with Android SDK can also use it.
uiautomatorviewer) Get the resourceId and other attributes of the interface element
3.2 Complete executable code
The code has built-in random like probability, random comment probability, and degradation strategies for multiple element positioning. You can copy and run directly.
Summarize
-
**How to choose tools? ** Android lightweight crawler/quick script → uiautomator2 Games / Complex UI cannot be parsed → Airtest Cross-platform (Android + iOS) formal testing → Appium
-
Element positioning priority
resourceId>contentDescription>textMatches>图像识别 -
Anti-climbing three-piece set Conditional waiting + random delay, random sliding distance/duration, random offset click coordinates
-
The last red line All the techniques in this article are only for learning and communication. Do not conduct large-scale brushing or illegal crawling.
As long as you master this set of ideas and template code, most introductory tasks for mobile UI automation can be implemented efficiently without being dragged along by cumbersome framework documents. I hope this minimalist guide really helps you.

