Appium-Python3--UI自动化-[-3-]-元素定位-获取APP中的toast,判断该元素是否存在

获取如图的toast提示

 

 

 

 

 直接上代码:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
 
def is_toast_exist(driver,text=None,timeout=30,poll_frequency=0.5):
 
   '''is toast exist, return True or False
   :Agrs:
    - driver - 传driver
    - text   - 页面上看到的文本内容
    - timeout - 最大超时时间,默认30s
    - poll_frequency  - 间隔查询时间,默认0.5s查询一次
   :Usage:
    is_toast_exist(driver, "看到的内容")
   '''
 
   try:
       toast_loc = ("xpath", ".//*[contains(@text,'%s')]"%text)
       WebDriverWait(driver, timeout, poll_frequency).until(EC.presence_of_element_located(toast_loc))
       return True
   except:
       return False
posted @ 2018-11-03 17:33  旅行没有终点  阅读(770)  评论(0编辑  收藏  举报