深入探索 uiautomator2: Android UI自动化的强大工具

1. 简介

     uiautomator2 是一个 Android UI自动化测试的 Python 包,允许控制和测试 Android 设备它是基于 Google 的 uiautomator 框架的二次开发。

GitHub :https://github.com/openatx/uiautomator2

2. 安装和环境配置

需要配置 Python 环境和安装 uiautomator2 第三方库:

首先安装 Python 的环境

此处省略安装步骤

Python 解释器 

建议使用 3.11 版本


使用命令来查看Python 版本

python --version

 安装命令

pip install uiautomator2

初始化设备

python -m uiautomator2 init

3. 基础使用教程
 

导入uiautomator2 库

import uiautomator2 as u2

连接设备

device = u2.connect_usb('7b068a46') 

点击操作

device.click(x, y)

输入文本

device.send_keys("text")

滚动查找 

device(scrollable=True).scroll.to(text="Settings")

4. 高级功能


XPath

element = device.xpath('//android.widget.TextView[@text="Settings"]').get()

控件组合查询

element = device(text="Settings", className="android.widget.TextView")

滚动

device(scrollable=True).scroll.to(text="phone")

5. 代码

 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值