Python - no such alert

2020-06-24  本文已影响0人  robotframe

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 

https://blog.csdn.net/m0_38080393/article/details/96318466

上一篇 下一篇

猜你喜欢

热点阅读