码迷,mamicode.com
首页 > 移动开发 > 详细

Appium获取toast消息(二)

时间:2018-09-19 19:59:53      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:def   解决方法   pre   代码   wait   内容   sele   except   col   

刚接触appium进行移动端设备的UI自动化,在遇到toast消息的时候很是苦恼了一阵,最后通过强大的搜索引擎找到了个相对解决方法,废话不多说,直接贴代码↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓:

 1 from selenium.webdriver.support.ui import WebDriverWait
 2 from selenium.webdriver.support import expected_conditions as EC
 3  
 4 def is_toast_exist(driver,text=None,timeout=30,poll_frequency=0.5):
 5  
 6    ‘‘‘is toast exist, return True or False
 7    :Agrs:
 8     - driver - 传driver
 9     - text   - 页面上看到的文本内容
10     - timeout - 最大超时时间,默认30s
11     - poll_frequency  - 间隔查询时间,默认0.5s查询一次
12    :Usage:
13     is_toast_exist(driver, "看到的内容")
14    ‘‘‘
15  
16    try:
17        toast_loc = ("xpath", ".//*[contains(@text,‘%s‘)]"%text)
18        WebDriverWait(driver, timeout, poll_frequency).until(EC.presence_of_element_located(toast_loc))
19        return True
20    except:
21        return False

如果还有更好的方法,欢迎在评论区留言,共同学习

 

Appium获取toast消息(二)

标签:def   解决方法   pre   代码   wait   内容   sele   except   col   

原文地址:https://www.cnblogs.com/soner/p/9676048.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!