下载免安装python3.8
https://www.python.org/ftp/python/3.8.0/python-3.8.0-amd64.exe
不要使用3.9暂时不兼容pillow等插件
3.8免安装版
要单独安装progress‑1.5‑py2.py3‑none‑any.whl插件
更新pip
python -m pip install --upgrade pip
安装UIAutomator2
pip3 install --pre -U uiautomator2
初始化UIAutomator2
python -m uiautomator2 init
安装后模拟器能看到一个ATX app (win环境没有)
C:\Users\Administrator>python -m uiautomator2 init
[I 200411 21:07:04 init:154] uiautomator2 version: 2.7.1
[I 200411 21:07:04 init:347] Install minicap, minitouch
[D 200411 21:07:04 init:58] Use cached assets: C:\Users\Administrator\.uiautomator2\cache\minitouch-7b41fbda87\minitouch
[D 200411 21:07:04 init:231] Push to /data/local/tmp/minitouch:0755
[I 200411 21:07:04 init:350] abi:x86 seems to be android emulator, skip install minicap
[D 200411 21:07:04 init:249] apk-debug package-info: {'version_name': '2.3.1', 'version_code': '2003001', 'flags': ['DEBUGGABLE', 'HAS_CODE', 'ALLOW_CLEAR_USER_DATA', 'ALLOW_BACKUP'], 'first_install_time': datetime.datetime(2020, 4, 11, 14, 35, 41), 'last_update_time': datetime.datetime(2020, 4, 11, 14, 35, 41), 'signature': '37f827cf'}
[D 200411 21:07:04 init:250] apk-debug-test package-info: {'version_name': '', 'version_code': '', 'flags': ['DEBUGGABLE', 'HAS_CODE', 'ALLOW_CLEAR_USER_DATA', 'ALLOW_BACKUP'], 'first_install_time': datetime.datetime(2020, 4, 11, 14, 35, 43), 'last_update_time': datetime.datetime(2020, 4, 11, 14, 35, 43), 'signature': '3d2d4b48'}
[I 200411 21:07:04 init:365] Already installed com.github.uiautomator apks
[D 200411 21:07:04 init:285] Real version: [0, 9, 4], Expect version: [0, 9, 4]
[D 200411 21:07:04 init:161] Shell: ('/data/local/tmp/atx-agent', 'server', '--nouia', '-d')
[I 200411 21:07:04 init:372] Check atx-agent version
[D 200411 21:07:04 init:382] Forward: local:tcp:59674 -> remote:tcp:7912
[D 200411 21:07:04 init:385] atx-agent version 0.9.4
Successfully init AdbDevice(serial=emulator-5554)
adb connect 192.168.2.12
编写python脚本 iffyhello.py
import uiautomator2 as ua
device = ua.connect("192.168.2.12:5555")
print(device)
device.app_start('com.android.settings', '.Settings')
device(text="WLAN").click()
运行脚本
python iffyhello.py
元素定位插件
pip install weditor -i https://pypi.tuna.tsinghua.edu.cn/simple/
运行 元素定位插件 python -m weditor