1. 安裝ADB
地址:https://developer.android.google.cn/studio/releases/platform-tools?hl=en
下載對(duì)應(yīng)環(huán)境的工具 解壓

之后設(shè)置環(huán)境變量
右鍵我的電腦->屬性 然后按下圖順序 最后添加platform-tools的路徑保存即可

設(shè)置好后cmd打開(kāi)命令行
輸入adb version
可以查看adb版本信息 ok~

2. 安裝uiautomator2
python下載uiautomator2包
pip install --pre uiautomator2
使用數(shù)據(jù)線將手機(jī)與電腦相連 使用開(kāi)發(fā)者模式
在電腦命令行輸入
python -m uiautomator2 init
進(jìn)行初始化
手機(jī)同一安裝atx 和com.github.uiautomator.test
如果需要wifi連接 adb需要tcpip連接模式
所以在數(shù)據(jù)線連接時(shí)我們需要設(shè)定端口
3.測(cè)試連接
手機(jī)與電腦連接同一個(gè)局域網(wǎng)
手機(jī)連接wifi后 ip為 192.168.0.102
adb連接手機(jī)設(shè)備

python測(cè)試如下
import uiautomator2 as u2
#d = u2.connect() # 有線連接,手機(jī)需要插電腦上
d = u2.connect("192.168.0.102:5566") #通過(guò)無(wú)線連接,電腦和手機(jī)需要在同一個(gè)局域網(wǎng)內(nèi),并且需要先用有線的方式做過(guò)初始化
print(d.info)
輸出設(shè)備信息
{‘currentPackageName': ‘com.bbk.launcher2', ‘displayHeight': 2160, ‘displayRotation': 0, ‘displaySizeDpX': 360, ‘displaySizeDpY': 720, ‘displayWidth': 1080, ‘productName': ‘PD1709', ‘screenOn': True, ‘sdkInt': 27, ‘naturalOrientation': True}
連接成功
到此這篇關(guān)于python 使用uiautomator2連接手機(jī)設(shè)備的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)python uiautomator2連接手機(jī)設(shè)備內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
您可能感興趣的文章:- Python繪圖庫(kù)Matplotlib的基本用法
- Python matplotlib實(shí)用繪圖技巧匯總
- Python+uiautomator2實(shí)現(xiàn)手機(jī)鎖屏解鎖功能
- Python+uiautomator2實(shí)現(xiàn)自動(dòng)刷抖音視頻功能
- python使用matplotlib顯示圖像失真的解決方案
- 基于python的matplotlib制作雙Y軸圖
- 用Python的繪圖庫(kù)(matplotlib)繪制小波能量譜
- python matplotlib繪圖實(shí)現(xiàn)刪除重復(fù)冗余圖例的操作
- Python基礎(chǔ)之畫(huà)圖神器matplotlib
- python保存大型 .mat 數(shù)據(jù)文件報(bào)錯(cuò)超出 IO 限制的操作