如何使用 python Selenium 关闭动态弹出窗口

时间:2021-03-24 14:56:22

标签: python python-3.x selenium selenium-chromedriver webdriverwait

我想关闭这个弹出窗口,但我不能, 我曾尝试使用 find.element.by.xpath() 我猜有所有不同的可能性, 尝试使用 switch_to _alert().dismiss() 但似乎没有任何帮助 任何帮助深表感谢, 谢谢

enter image description here

1 个答案:

答案 0 :(得分:1)

似乎不是警报。它只是网页上的另一个元素。

Induce WebDriverWait() 并等待 element_to_be_clickable() 和后面的 css 选择器

WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"div#dismiss-button"))).click()

您需要导入以下库。

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

注意:如果出现超时错误,请检查该元素是否在 iframe 下。如果是这样,您需要切换到 iframe 以交互按钮元素。

相关问题