<tfoot id='ewIDT'></tfoot>
  • <small id='ewIDT'></small><noframes id='ewIDT'>

    <i id='ewIDT'><tr id='ewIDT'><dt id='ewIDT'><q id='ewIDT'><span id='ewIDT'><b id='ewIDT'><form id='ewIDT'><ins id='ewIDT'></ins><ul id='ewIDT'></ul><sub id='ewIDT'></sub></form><legend id='ewIDT'></legend><bdo id='ewIDT'><pre id='ewIDT'><center id='ewIDT'></center></pre></bdo></b><th id='ewIDT'></th></span></q></dt></tr></i><div id='ewIDT'><tfoot id='ewIDT'></tfoot><dl id='ewIDT'><fieldset id='ewIDT'></fieldset></dl></div>

    <legend id='ewIDT'><style id='ewIDT'><dir id='ewIDT'><q id='ewIDT'></q></dir></style></legend>

        <bdo id='ewIDT'></bdo><ul id='ewIDT'></ul>

      1. Webdriver 错误:“不存在警报"在抛出 UnexpectedAlertPresentException

        时间:2023-07-05

          <bdo id='ganmD'></bdo><ul id='ganmD'></ul>

          <tfoot id='ganmD'></tfoot>
              1. <i id='ganmD'><tr id='ganmD'><dt id='ganmD'><q id='ganmD'><span id='ganmD'><b id='ganmD'><form id='ganmD'><ins id='ganmD'></ins><ul id='ganmD'></ul><sub id='ganmD'></sub></form><legend id='ganmD'></legend><bdo id='ganmD'><pre id='ganmD'><center id='ganmD'></center></pre></bdo></b><th id='ganmD'></th></span></q></dt></tr></i><div id='ganmD'><tfoot id='ganmD'></tfoot><dl id='ganmD'><fieldset id='ganmD'></fieldset></dl></div>

                  <small id='ganmD'></small><noframes id='ganmD'>

                  <legend id='ganmD'><style id='ganmD'><dir id='ganmD'><q id='ganmD'></q></dir></style></legend>

                    <tbody id='ganmD'></tbody>
                • 本文介绍了Webdriver 错误:“不存在警报"在抛出 UnexpectedAlertPresentException 之后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试测试我正在开发的 web 应用程序.我正在使用针对 Firefox 22.0 的 Firefox 驱动程序.

                  I'm trying to test a webapp I'm developing. I'm using the Firefox driver against Firefox 22.0.

                  在某一时刻,可能会弹出一个模式对话框(Javascript prompt()).如果是这样,我想输入一些文本,然后将其关闭(单击确定).

                  At one point, a modal dialog may pop up (a Javascript prompt()). If it does, I want to enter some text and then dismiss it (click OK).

                  以下是相关代码:

                  try:
                      if button.text == "Run":
                          button.click()
                  except UnexpectedAlertPresentException:
                      alert = self.driver.switch_to_alert()
                      print alert.text
                      alert.send_keys('8080')
                      alert.dismiss()
                  

                  UnexpectedAlertPresentException 正在被抛出.但是,一旦它尝试执行 print alert.text,我就会得到:

                  The UnexpectedAlertPresentException is being thrown. However, as soon as it tries to execute print alert.text, I get:

                  `NoAlertPresentException: Message: u'No alert is present'`.
                  

                  如果我删除打印语句,它会在 alert.send_keys 处爆炸:

                  If I remove the print statement, it blows up at alert.send_keys with:

                  `WebDriverException: Message: u'fxdriver.modals.find_(...) is null'`
                  

                  我不明白.NoAlertPresentException 根据定义是否与抛出并导致异常块首先执行的 UnexpectedAlertPresentException 相矛盾?

                  I don't get it. Isn't the NoAlertPresentException by definition contradicting the UnexpectedAlertPresentException that was thrown and caused the except block to be executed in the first place?

                  另外,我无法在 UnexpectedAlertPresentException 的任何文档/api/py/index.html#documentation">http://selenium.googlecode.com/svn/trunk/docs/api/py/index.html#documentation

                  Also, I can't for the life of me find any documentation on the UnexpectedAlertPresentException in http://selenium.googlecode.com/svn/trunk/docs/api/py/index.html#documentation

                  编辑 2:这就是我现在所拥有的:

                  Edit 2: This is what I have now:

                  try:
                      if button.text == "Run":
                          button.click()
                  
                          alert = self.driver.switch_to_alert()
                  
                          alert.send_keys('1111')
                          alert.dismiss()
                  
                   except NoAlertPresentException:
                       pass
                  

                  但是,我仍然看到这个:

                  However, I'm still seeing this:

                  WebDriverException: Message: u'fxdriver.modals.find_(...) is null' 
                  

                  alert.send_keys('8080') 行上.我想我不明白如果没有警报,为什么 switch_to_alert() 不抛出 NoAlertPresent ......这就是我假设 WebDriverException 表示.

                  on the line alert.send_keys('8080'). I guess I don't understand why switch_to_alert() doesn't throw NoAlertPresent if there isn't an alert...which is what I'm assuming the WebDriverException is indicating.

                  推荐答案

                  我认为 Selenium 会关闭意外警报.显然,您可以更改 Firefox 驱动程序处理意外警报的方式:如何使用UnexpectedAlertBehaviour"处理警报Selenium 的能力?

                  I think Selenium closes unexpected alerts. Apparently you can change how the firefox driver treats unexpected alerts: How to handle an Alert with "UnexpectedAlertBehaviour" capability in Selenium?

                  作为替代方案,您可以在采取行动之前检查是否有警报(毕竟,如果您想处理警报,这并不意外),就像这样(Java):

                  As an alternative, you could check if there is an alert before acting (after all, if you want handle the alert it's not unexpected) like so (Java):

                  try {
                    Alert alert = _driver.switchTo().alert();
                    //do stuff with alert
                  } catch (final NoAlertPresentException e) {
                    //do non-alert stuff
                  }
                  

                  这篇关于Webdriver 错误:“不存在警报"在抛出 UnexpectedAlertPresentException 之后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 Selenium 通过 PhantomJS 中的超链接下载文件 下一篇:如何使用 Python + Selenium 从警报框中读取文本

                  相关文章

                  • <bdo id='DWCmE'></bdo><ul id='DWCmE'></ul>

                  <legend id='DWCmE'><style id='DWCmE'><dir id='DWCmE'><q id='DWCmE'></q></dir></style></legend>
                  <i id='DWCmE'><tr id='DWCmE'><dt id='DWCmE'><q id='DWCmE'><span id='DWCmE'><b id='DWCmE'><form id='DWCmE'><ins id='DWCmE'></ins><ul id='DWCmE'></ul><sub id='DWCmE'></sub></form><legend id='DWCmE'></legend><bdo id='DWCmE'><pre id='DWCmE'><center id='DWCmE'></center></pre></bdo></b><th id='DWCmE'></th></span></q></dt></tr></i><div id='DWCmE'><tfoot id='DWCmE'></tfoot><dl id='DWCmE'><fieldset id='DWCmE'></fieldset></dl></div>

                  <tfoot id='DWCmE'></tfoot>

                  <small id='DWCmE'></small><noframes id='DWCmE'>