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

就可以了

相关推荐
全栈练习生9 小时前
AI Agent 沙箱
python·ai
SEO_juper10 小时前
用 Python 写一个 GEO 可见性检查脚本:你的网站现在能被 AI 引用吗
开发语言·人工智能·爬虫·python·seo·外贸独立站
用户83562907805111 小时前
使用 Python 对 Excel 工作表进行排序
后端·python
for_ever_love__12 小时前
MySQL 全文索引实战:FULLTEXT、ngram 中文分词与 MATCH AGAINST 到底该怎么用
java·python·mysql·全文检索·分词·索引·ngram
用户83562907805112 小时前
使用 Python 合并 PowerPoint 演示文稿
后端·python
weixin_4617694012 小时前
VS Code 中创建 Jupyter 文件(.ipynb)
ide·python·jupyter
2601_9669496512 小时前
多市场量化策略的数据接口应该如何设计:从数据层架构到策略接入
开发语言·python·数据分析·pandas·量化交易·股票数据·quantdash
全栈弄潮儿12 小时前
Python实战第1期:Python环境搭建与第一个程序
python
心易行者13 小时前
Agent应用+API端点商业化进阶实战:从单体智能体到可付费调用的API全流程
运维·服务器·人工智能·python·apache
weixin1997010801613 小时前
《1688图片空间API踩坑:img.upload 与 album.* 的防盗链与CDN缓存问题》(附Python源码)
开发语言·python·缓存