python uiautomator2连接手机设备 python 使用uiautomator2连接手机设备的实现

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

python uiautomator2连接手机设备 python 使用uiautomator2连接手机设备的实现

alphaTao   2021-04-30 我要评论
想了解python 使用uiautomator2连接手机设备的实现的相关内容吗,alphaTao在本文为您仔细讲解python uiautomator2连接手机设备的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:python,uiautomator2连接手机设备,python,uiautomator2,下面大家一起来学习吧。

1. 安装ADB

地址:https://developer.android.google.cn/studio/releases/platform-tools?hl=en
下载对应环境的工具 解压

在这里插入图片描述

之后设置环境变量

右键我的电脑->属性 然后按下图顺序 最后添加platform-tools的路径保存即可

在这里插入图片描述

设置好后cmd打开命令行

输入adb version

可以查看adb版本信息 ok~

在这里插入图片描述

2. 安装uiautomator2

python下载uiautomator2包

pip install --pre uiautomator2

使用数据线将手机与电脑相连 使用开发者模式
在电脑命令行输入

python -m uiautomator2 init

进行初始化
手机同一安装atx 和com.github.uiautomator.test

如果需要wifi连接 adb需要tcpip连接模式
所以在数据线连接时我们需要设定端口

adb tcpip 5566

3.测试连接

手机与电脑连接同一个局域网
手机连接wifi后 ip为 192.168.0.102
adb连接手机设备

在这里插入图片描述

python测试如下

import uiautomator2 as u2
#d = u2.connect()  # 有线连接,手机需要插电脑上 
d = u2.connect("192.168.0.102:5566") #通过无线连接,电脑和手机需要在同一个局域网内,并且需要先用有线的方式做过初始化
print(d.info)

输出设备信息

{‘currentPackageName': ‘com.bbk.launcher2', ‘displayHeight': 2160, ‘displayRotation': 0, ‘displaySizeDpX': 360, ‘displaySizeDpY': 720, ‘displayWidth': 1080, ‘productName': ‘PD1709', ‘screenOn': True, ‘sdkInt': 27, ‘naturalOrientation': True}

连接成功

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们