python - 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))
解决方案
您可以为此使用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、名称等)。
希望对你有帮助!
推荐阅读
- excel - 有选择地将行从一个工作表复制到新工作表上的新表
- dataframe - 在具有相同标题名称的单个数据框中按行连接多个文件
- ruby-on-rails - 在 Rails 中实现 Bootstrap 主题
- github - 在 GitHub 上更改或删除提交消息?
- jquery - 如何在除一个 div 之外的所有 div 中选择所有 div 类
- mysql - SQL 来自同一列的多个值与内部连接
- javascript - 忽略单词并删除区分大小写和空格以匹配
- python - 如何在 lambda 函数中使用时间序列索引
- function - 我无法让 CSS 应用于打印表
- php - 在 PHP 中匹配日期时间