獲取如圖的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