Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在处理UnexpectedAlertPresentException期间,python中会发生NoAlertPresentException_Python_Selenium_Selenium Webdriver_Webdriver - Fatal编程技术网

在处理UnexpectedAlertPresentException期间,python中会发生NoAlertPresentException

在处理UnexpectedAlertPresentException期间,python中会发生NoAlertPresentException,python,selenium,selenium-webdriver,webdriver,Python,Selenium,Selenium Webdriver,Webdriver,我正在处理经常发生的意外AlertPresentException,所以我使用了try-except代码来处理它。我正要返回意外警报的内容,所以我的代码是 wait = WebDriverWait(driver2, 10) try: element = wait.until(EC.element_to_be_clickable((By.NAME, 'wlike_limit'))) except UnexpectedAlertPresentException: print(&quo

我正在处理经常发生的意外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 

UnexpectedAlertPresentException回溯(最近一次调用)
在里面
16尝试:
--->17 element=wait.until(EC.element可点击((By.NAME,'wlike\u limit'))
18除意外的AlertPresentException外:
UnexpectedAlertPresentException:警报文本:
消息:意外警报打开:{警报文本:}
(会话信息:chrome=84.0.4147.125)
在处理上述异常期间,发生了另一个异常:
NoAlertPresentException回溯(最后一次最近调用)
在里面
17 element=wait.until(EC.element可点击((By.NAME,'wlike\u limit'))
18除意外的AlertPresentException外:
--->19打印(“UnexpectedAlertPresentException,”,driver2.switch_to.alert.text)
20
有人能帮我解决这个问题吗?

此错误消息

NoAlertPresentException                   Traceback (most recent call last)
…意味着虽然您试图处理一个问题,但没有这样的问题


分析 这行代码:

except UnexpectedAlertPresentException:
        print("UnexpectedAlertPresentException, ",driver2.switch_to.alert.text)
        
当代码块遇到意外的AlertPresentException时,将切换到警报并检索文本。然而,目前似乎没有警报

现在在
try{}
块中:

element = wait.until(EC.element_to_be_clickable((By.NAME, 'wlike_limit')))
此行不会引发任何警报,因为您没有与元素交互。因此,捕获
UnexpectedAlertPresentException
对我来说似乎没有什么用处


结论 处理
UnexpectedAlertPresentException
try-catch{}
块对我来说似乎没有什么用处。也许您以前的代码块可以提供一些提示,说明您希望在哪些情况下处理UnexpectedAlertPresentException


工具书类 您可以在以下内容中找到一些相关讨论:

此错误消息

NoAlertPresentException                   Traceback (most recent call last)
…意味着虽然您试图处理一个问题,但没有这样的问题


分析 这行代码:

except UnexpectedAlertPresentException:
        print("UnexpectedAlertPresentException, ",driver2.switch_to.alert.text)
        
当代码块遇到意外的AlertPresentException时,将切换到警报并检索文本。然而,目前似乎没有警报

现在在
try{}
块中:

element = wait.until(EC.element_to_be_clickable((By.NAME, 'wlike_limit')))
此行不会引发任何警报,因为您没有与元素交互。因此,捕获
UnexpectedAlertPresentException
对我来说似乎没有什么用处


结论 处理
UnexpectedAlertPresentException
try-catch{}
块对我来说似乎没有什么用处。也许您以前的代码块可以提供一些提示,说明您希望在哪些情况下处理UnexpectedAlertPresentException


工具书类 您可以在以下内容中找到一些相关讨论: