如何获取app中的toast弹窗
Appium 1116
APP中进行保存时有保存成功或失败的提示,是使用toast弹窗进行提示的,但是用一般的方法不能定位到toast弹窗,需要用什么方法获取toast弹窗呢
-
引入Uiautomator2,使用WebDriverWait显示等待,等待页面加载完成,找到某个条件发生后再继续执行后续代码,如果超过设置时间检测不到则抛出异常。
def get_toast_text(self, text, timeout=5, poll_frequency=0.01):
“””
########################################
描述:获取Toast的文本信息
参数:text需要检查的提示信息 time检查总时间 poll_frequency检查时间间隔
返回值:返回与之匹配到的toast信息
异常描述:none
########################################
“””
toast_element = (By.XPATH, “//*[contains(@text, ” + “‘” + text + “‘” + “)]”)
toast = WebDriverWait(self.driver, timeout,poll_frequency).until(EC.presence_of_element_located(toast_element))
return toast.text6年前