【问题标题】:Alert Popup Exception Handling Python Selenium警报弹出异常处理 Python Selenium
【发布时间】:2018-11-10 19:22:40
【问题描述】:

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

#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 : ...}

【问题讨论】:

  • 你能告诉我们警报网址或代码吗
  • 您正在尝试处理警报,以防没有警报!也许您应该在 try 和 except 块中切换代码?
  • 这是尝试,除了...
  • 切换到默认内容不应导致触发警报。请发布导致警报触发的相关代码。这就是您需要try-catch 的地方。

标签: python selenium error-handling


【解决方案1】:

您似乎使用了错误的selenium.common.exceptions 根据错误消息,这似乎是一个意外警报。我会尝试使用UnexpectedAlertPresentException 而不是NoAlertPresentException

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-21
    • 2015-09-21
    • 2023-01-02
    • 1970-01-01
    • 2015-03-06
    • 2015-12-16
    • 1970-01-01
    相关资源
    最近更新 更多