<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

        Webdriver error: quot;No alert is presentquot; after UnexpectedAlertPresentException is thrown(Webdriver 错误:“不存在警报在抛出 UnexpectedAlertPresentException 之后)

          <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 之后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  env: python: No such file or directory(env: python: 没有这样的文件或目录)
                  How to evaluate environment variables into a string in Python?(如何在 Python 中将环境变量评估为字符串?)
                  Python - temporarily modify the current process#39;s environment(Python - 临时修改当前进程的环境)
                  Change current process environment#39;s LD_LIBRARY_PATH(更改当前进程环境的 LD_LIBRARY_PATH)
                  Reading and writing environment variables in Python?(在 Python 中读写环境变量?)
                  When to use sys.path.append and when modifying %PYTHONPATH% is enough(何时使用 sys.path.append 以及何时修改 %PYTHONPATH% 就足够了)
                  • <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'>

                              <tbody id='DWCmE'></tbody>