如何使用uiautomator2+Weditor 可视化查看一个app组件的vm树

1、安装uiautomator2

bash 复制代码
pip show uiautomator2

2、验证安装

c 复制代码
pip show uiautomator2

如果能看到版本号,说明安装好了。

记得初始化手机哦(如果没做过): 在命令行运行:
uiautomator2 init

ps:文件夹是空的,不像zip有相关文件

3、运行

如果你是批量查看那么写一个脚本

python 复制代码
import uiautomator2 as u2
import time

d = u2.connect()

# 1. 启动你想看的 App (比如设置页面)
# "com.android.settings" 是设置的包名,你需要换成你要测的 App 包名
d.app_start("com.android.settings")

# 2. 等待几秒,确保 App 完全打开了,否则可能打印到启动时的白屏
time.sleep(3)

# 3. 现在的 hierarchy 就是这个 App 的了
xml = d.dump_hierarchy()
print(xml)

或者使用Weditor静态定格分析

第一步:手机连接电脑

第二步:启动Weditor

python 复制代码
python -m weditor

然后浏览器会自动打开(通常是 http://localhost:17310

如果出现以下问题:

是因为Python 的库是跟着解释器走的。如果你之前在 Python 其他版本里装的 weditor,更换新的python版本就需要重新安装

解决方法:

cmd运行以下代码

python 复制代码
E:\python3.10.11\python.exe -m pip install weditor uiautomator2

然后输入以下命令运行

python 复制代码
E:\python3.10.11\python.exe -m weditor

如果遇到这个问题

先退出当前目录

python 复制代码
cd ..

然后升级 pip 并重新安装,输入以下命令

python 复制代码
 E:\python3.10.11\python.exe -m pip install --upgrade pip
python 复制代码
E:\python3.10.11\python.exe -m pip install weditor uiautomator2

然后运行

python 复制代码
E:\python3.10.11\python.exe -m weditor

还出现错误就到python所在的那个盘

python 复制代码
cd /d E:\
python 复制代码
E:\python3.10.11\python.exe -m pip install weditor

然后

python 复制代码
python.exe -m weditor

就可以了

相关推荐
用户8356290780511 天前
无需 Office:Python 批量转换 PPT 为图片
后端·python
markfeng81 天前
Python+Django+H5+MySQL项目搭建
python·django
GinoWi1 天前
Chapter 2 - Python中的变量和简单的数据类型
python
JordanHaidee1 天前
Python 中 `if x:` 到底在判断什么?
后端·python
ServBay1 天前
10分钟彻底终结冗长代码,Python f-string 让你重获编程自由
后端·python
闲云一鹤1 天前
Python 入门(二)- 使用 FastAPI 快速生成后端 API 接口
python·fastapi
Rockbean1 天前
用40行代码搭建自己的无服务器OCR
服务器·python·deepseek
曲幽1 天前
FastAPI + Ollama 实战:搭一个能查天气的AI助手
python·ai·lora·torch·fastapi·web·model·ollama·weatherapi
用户60648767188961 天前
国内开发者如何接入 Claude API?中转站方案实战指南(Python/Node.js 完整示例)
人工智能·python·api
只与明月听1 天前
RAG深入学习之Chunk
前端·人工智能·python