首页 > 解决方案 > Python + Selenium:等待网络元素消失

问题描述

我使用 WebDriver 等等,但我有一个问题。页面上出现一个元素,该元素在 3 秒后消失。我想停止这次测试并在这段时间之后恢复测试(不睡觉)。我怎么能做到这一点?我与 WebDriver 相关:

WebDriverWait(self.driver, 15, poll_frequency=0.5, ignored_exceptions[ElementNotVisibleException, ElementNotSelectableException,NoSuchElementException, WebDriverException]).until(expected_conditions.element_to_be_clickable(FormPage.name))

标签: pythonselenium

解决方案


您可以为此使用invisibility_of_element_located预期条件:

from selenium.webdriver.support import ui
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By


ui.WebDriverWait(self.driver, 15).until(EC.invisibility_of_element_located((By.CSS_SELECTOR, "your_css_selector")))

PS:您可以使用任何其他定位器(ID、名称等)。

希望对你有帮助!


推荐阅读