实现代码如下:
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC class toast: def is_toast_exist(self,driver,text,timeout=30, poll_frequency=0.5): 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