Python+Selenium:等待web元素的消失

2024-10-02 22:23:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我用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))

Tags: self元素driver页面exceptionsfrequencywebdriverpoll
1条回答
网友
1楼 · 发布于 2024-10-02 22:23:11

您可以使用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、名称等)。你知道吗

希望对你有帮助!你知道吗

相关问题 更多 >