当前位置:网站首页>uiautomator2 常用命令
uiautomator2 常用命令
2022-07-25 07:43:00 【风华绝代一只猫】
原文来自:https://github.com/openatx/uiautomator2/blob/master/QUICK_REFERENCE.md
import uiautomator2 as u2
d = u2.connect(“–serial-here–”) # 只有一个设备也可以省略参数
d = u2.connect() # 一个设备时
d = u2.connect(“10.1.2.3”) # 通过设备的IP连接(需要在同一局域网且设备上的atx-agent已经安装并启动)
d.app_current() # 获取前台应用 packageName, activity
d.app_start(“com.example.app”) # 启动应用
d.app_start(“com.example.app”, stop=True) # 启动应用前停止应用
d.app_stop(“com.example.app”) # 停止应用
app = d.session(“com.example.app”) # 启动应用并获取session
session的用途是操作的同时监控应用是否闪退,当闪退时操作,会抛出SessionBrokenError
app.click(10, 20) # 坐标点击
无session状态下操作
message_a=d.toast.get_message() #获取toast
d.click(10, 20) # 坐标点击
d.swipe(10, 20, 80, 90) # 从(10, 20)滑动到(80, 90)
d.swipe_ext(“right”) # 整个屏幕右滑动
d.swipe_ext(“right”, scale=0.9) # 屏幕右滑,滑动距离为屏幕宽度的90%
d.press(“back”) # 模拟点击返回键
d.press(“home”) # 模拟Home键
d.send_keys(“hello world”) # 模拟输入,需要光标已经在输入框中才可以
d.clear_text() # 清空输入框
执行shell命令
output, exit_code = d.shell(“ps -A”, timeout=60) # 执行shell命令,获取输出和exitCode
output = d.shell(“pwd”).output # 这样也可以
exit_code = d.shell(“pwd”).exit_code # 这样也可以
元素操作
d.xpath(“立即开户”).wait() # 等待元素,最长等10s(默认)
d.xpath(“立即开户”).wait(timeout=10) # 修改默认等待时间
常用配置
d.settings[‘wait_timeout’] = 20 # 控件查找默认等待时间(默认20s)
xpath操作
d.xpath(“立即开户”).click() # 包含查找等待+点击操作,匹配text或者description等于立即开户的按钮
d.xpath(“//*[@text=‘私人FM’]/…/android.widget.ImageView”).click()
d.xpath(‘//*[@text=“私人FM”]’).get().info # 获取控件信息
for el in d.xpath(‘//android.widget.EditText’).all():
print(“rect:”, el.rect) # output tuple: (left_x, top_y, width, height)
print(“bounds:”, el.bounds) # output tuple: (left, top, right, bottom)
print(“center:”, el.center())
el.click() # click operation
print(el.elem) # 输出lxml解析出来的Node
监控弹窗(在线程中监控)
d.watcher.when(“跳过”).click()
d.watcher.start()
边栏推荐
- [unity introduction program] basic concepts - 2D collider collider 2D
- DJI push code (one code for one use, limited time push)
- RPC communication principle and project technology selection
- [pytorch] the most common function of view
- diagramscene工程难点分析
- 【Unity入门计划】基本概念-触发器 Trigger
- Problems in deep learning training and testing: error: the following arguments are required: --dataroot, solution: the configuration method of training files and test files
- [unity introduction plan] interface Introduction (2) -games view & hierarchy & Project & Inspector
- [programmer 2 Civil Servant] IV. common problems
- P1046 [NOIP2005 普及组 T1] 陶陶摘苹果
猜你喜欢

Today in history: Intel was founded; The first photo was posted on the world wide web; EBay spins off PayPal

A fast method of data set enhancement for deep learning
P1086 [NOIP2004 普及组第二题] 花生采摘

Hikaricp connection pool does not operate for a period of time, and the data is automatically disconnected

【Unity入门计划】基本概念-2D碰撞体Collider 2D

【Unity入门计划】基本概念-触发器 Trigger

【Unity入门计划】基本概念-预制件 Prefab
![[paper notes] effective CNN architecture design guided by visualization](/img/aa/aeeac3f970eac7f110987c523602c8.png)
[paper notes] effective CNN architecture design guided by visualization

【Unity入门计划】基本概念-2D刚体Rigidbody 2D

How to reverse a stack with recursive functions and stack operations only
随机推荐
diagramscene工程难点分析
Problems during nanodet training: modulenotfounderror: no module named 'nanodet' solution
Analysis of common classes of Servlet
2-6.自动化采集
When deep learning makes data sets, it specifies how many frames to extract an image from the long video to the specified file path
toolbar的使用
JS note 17: the whole process of jest project configuration of typescript project
Install homebrew, NVM and verdaccio to build a private NPM warehouse
Talk about programmers learning English again
Teach you to use cann to convert photos into cartoon style
If Debian infringes the rust trademark, will it be exempted by compromising and renaming?
9 best engineering construction project management systems
全新8.6版本SEO快排系统(可源码级搭建)
Leetcode (Sword finger offer) - 04. search in two-dimensional array
ACNet:用于图像超分的非对称卷积(附实现code)
用一个栈实现另一个栈的排序
Analysis of difficulties in diagramscene project
Today in history: Intel was founded; The first photo was posted on the world wide web; EBay spins off PayPal
[pytorch] the most common function of view
Design of workflow system