zoukankan      html  css  js  c++  java
  • Appium_python3 抓取客户端toast

    在客户端登录或者退出登录的时候会有吐司提示,因此需要抓取来验证用户登录成功或者注销成功;

    在获取toast之前需要添加   desired_caps['automationName'] = 'Uiautomator2' , 否则无法获取到toast

     调用toast方法一:

    def is_toast_exist(self,driver, text=None, timeout=8, poll_frequency=0.01):
    try:
    toast_loc = ("xpath", ".//*[contains(@text,'%s')]" % text)
    WebDriverWait(driver, timeout, poll_frequency).until(EC.presence_of_element_located(toast_loc))
    return True
    except Exception as e:
    return False

    调用toast方法二:
    def get_toast_text(self, text, timeout=5, poll_frequency=0.01):
    try:
    toast_element = (By.XPATH, "//*[contains(@text, " + "'" + text + "'" + ")]")
    toast = WebDriverWait(self.driver, timeout, poll_frequency).until(EC.presence_of_element_located(toast_element))
    return toast.text
    except Exception as e:
    raise e
     
  • 相关阅读:
    Go语言http之请求接收和处理 代码
    C++之IO流的状态以及使用
    C++之指向函数的指针
    C++之数组类型的形参
    C++之vector类型的形参
    C++之形参
    C++之运算符
    C++之多维数组
    C++之动态数组
    C++之指针
  • 原文地址:https://www.cnblogs.com/jiguanghover/p/10696072.html
Copyright © 2011-2022 走看看