如何使用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

就可以了

相关推荐
FriendshipT29 分钟前
Ultralytics:解读 YOLO26 知识蒸馏
人工智能·pytorch·python·深度学习·yolo
BUG研究员_38 分钟前
工具绑定与调用
python·agent
苏灿烤鱼39 分钟前
AI Agent 深拆 | 图能让 AI 决策可追责吗?Semantica 登顶拆解
python·github·agent
Sirius.z9 小时前
第R6周:LSTM实现糖尿病探索与预测
python
名字还没想好☜9 小时前
Python f-string 进阶:数字格式化、对齐填充、调试 = 号与嵌套表达式
开发语言·数据库·python·字符串格式化·f-string
·薯条大王9 小时前
经济实惠玩云服务器|一台云服务器多人共用,子账号配置教程
java·linux·运维·服务器·汇编·c++·python
Dxy123931021610 小时前
Python 如何使用 MySQL 的事务
python·mysql
今儿敲了吗14 小时前
Python ——第三方包
笔记·python
麒麟水手14 小时前
国产银河麒麟系统开发实录:跑通Streamlit,我踩过的6个坑
python
麒麟水手15 小时前
麒麟系统部署检查清单:上线前30分钟,逐项自查这4类问题
python