【发布时间】:2021-06-21 07:40:17
【问题描述】:
我正在尝试关闭此弹出窗口,但我不能,
我试过使用find.element.by.xpath()
我猜有各种不同的可能性,
尝试使用switch_to _alert().dismiss() ,但似乎没有任何帮助
任何帮助深表感谢,
谢谢
【问题讨论】:
标签: python python-3.x selenium selenium-chromedriver webdriverwait
我正在尝试关闭此弹出窗口,但我不能,
我试过使用find.element.by.xpath()
我猜有各种不同的可能性,
尝试使用switch_to _alert().dismiss() ,但似乎没有任何帮助
任何帮助深表感谢,
谢谢
【问题讨论】:
标签: python python-3.x selenium selenium-chromedriver webdriverwait
似乎不是 警报。它只是网页上的另一个元素。
诱导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 才能与按钮元素进行交互。
【讨论】: