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
 
posted @ 2019-04-12 14:54  jiguanghover  阅读(207)  评论(0编辑  收藏  举报