python selenium中关闭网页弹出窗口用到了
driver.switch_to.alert.accept()
但是运行时报错:no such alert
解决方案:增加等待弹窗弹出时间,可以使用显式等待,当页面完全加载出弹出窗元素后再操作accept()
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
WebDriverWait(driver,20,0.5).until(EC.alert_is_present())
actual_alert=driver.switch_to.alert.text
refer to