我正在处理经常发生的意外AlertPresentException,所以我使用了try-except代码来处理它。我正要返回意外警报的内容,所以我的代码是
wait = WebDriverWait(driver2, 10)
try:
element = wait.until(EC.element_to_be_clickable((By.NAME, 'wlike_limit')))
except UnexpectedAlertPresentException:
print("UnexpectedAlertPresentException, ",driver2.switch_to.alert.text)
但在打印意外警报的文本时,它也会给我“NoAlertPresentException”
UnexpectedAlertPresentException Traceback (most recent call last)
<ipython-input-52-543c0fff5a64> in <module>
16 try:
---> 17 element = wait.until(EC.element_to_be_clickable((By.NAME, 'wlike_limit')))
18 except UnexpectedAlertPresentException:
UnexpectedAlertPresentException: Alert Text:
Message: unexpected alert open: {Alert text: }
(Session info: chrome=84.0.4147.125)
During handling of the above exception, another exception occurred:
NoAlertPresentException Traceback (most recent call last)
<ipython-input-52-543c0fff5a64> in <module>
17 element = wait.until(EC.element_to_be_clickable((By.NAME, 'wlike_limit')))
18 except UnexpectedAlertPresentException:
---> 19 print("UnexpectedAlertPresentException, ",driver2.switch_to.alert.text)
20
有人能帮我处理这个问题吗
此错误消息
…意味着虽然您试图处理Alert,但没有这样的alert
分析
这行代码:
当您的代码块面对UnexpectedAlertPresentException时,将切换到警报并检索文本。然而,目前似乎没有警报
现在在
try{}
块中:此行不会引发任何警报,因为您没有与元素交互。因此,捕捉
UnexpectedAlertPresentException
对我来说似乎没有什么用处结论
处理
UnexpectedAlertPresentException
的try-catch{}
块对我来说似乎没有用处。也许您以前的代码块可以提供一些提示,说明您希望在哪些情况下处理UnexpectedAlertPresentException参考资料
您可以在以下内容中找到一些相关讨论:
相关问题 更多 >
编程相关推荐