zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    数据结构笔记(一)
    Distance dependent Chinese Restaurant Processes
    距离依赖中餐馆过程
    AOP技术-02
    AOP技术-01
    Oracle-06
    web-02-css01
    web-02-css
    web-01
    jQuery对ajax的支持
  • 原文地址:https://www.cnblogs.com/chushujin/p/9901453.html
Copyright © 2011-2022 走看看