当前位置:网站首页>APP自动化uiautomator2获取toast
APP自动化uiautomator2获取toast
2022-08-02 19:38:00 【觅远】
源码:
def get_message(self,
wait_timeout=10,
cache_timeout=10,
default=None):
"""
Args:
wait_timeout: seconds of max wait time if toast now show right now
cache_timeout: return immediately if toast showed in recent $cache_timeout
default: default messsage to return when no toast show up
Returns:
None or toast message
"""自动获取toast,当有toast时,截图保存并语音播报:
import uiautomator2 as u2
import win32com.client
from datetime import datetime
d = u2.connect()
while True:
toast = d.toast.get_message(wait_timeout=5)
if toast:
print(toast) # 打印toast信息
d.screenshot('./IMG/%stoast.jpg' % datetime.now().strftime('%Y%m%d%H%M%S')) # 截图保存
speaker = win32com.client.Dispatch("SAPI.SpVoice") # 语音播放获取到的toast信息
speaker.Speak(toast)
d.toast.reset() # 在验证成功后及时清除缓存边栏推荐
猜你喜欢
随机推荐
治疗 | 如何识别和处理消极想法
清除浮动与BFC
A Review of Nature Microbiology: Focusing on the Algae--Ecological Interface of Phytoplankton-Bacteria Interactions
Caldera(一)配置完成的虚拟机镜像及admin身份简单使用
Dynamically generate different types of orders, how do I deposit to mongo database?
2022-07-26
golang刷leetcode 经典(13) 最小高度树
leetcode刷题记录:7.整数反转,8.字符串转整数,9.回文数
spack install报错/tmp/ccBDQNaB.s: Assembler message:
Redis cluster configuration
ALV报表学习总结
Compose主题切换——让你的APP也能一键换肤
【LeetCode】1161. 最大层内元素和
Detailed explanation of common examples of dynamic programming
shell:条件语句
EMQX Newsletter 2022-07|EMQX 5.0 正式发布、EMQX Cloud 新增 2 个数据库集成
Geoserver + mysql + openlayers problem
软件测试分类
Five data structures of Redis and their corresponding usage scenarios
服务器Centos7 静默安装Oracle Database 12.2








