首页 > 解决方案 > 警报弹出异常处理 Python Selenium

问题描述

我正在尝试进行警报异常处理,我尝试了一些选项,但我似乎无法让脚本尝试异常,它只是出错了。

#Add Alert Bypass
try:
    driver.switch_to.default_content()
except NoAlertPresentException:
    print('Alert Popup')
    alert = driver.switch_to.alert()
    alert.dismiss()

错误信息:

 Message: unexpected alert open: {Alert text : ...}

标签: pythonseleniumerror-handling

解决方案


看起来您使用了错误selenium.common.exceptions根据错误消息,它看起来像是一个意外警报。我会尝试使用UnexpectedAlertPresentException而不是NoAlertPresentException


推荐阅读