title: Webdriver error: "No alert is present" after UnexpectedAlertPresentException is thrown
body: <p>I'm trying to test a webapp I'm developing. I'm using the Firefox driver against Firefox 22.0.</p>
  
  <p>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).</p>
  
  <p>Here's the relevant code:</p>
  
  <pre><code>try:
      if button.text == "Run":
          button.click()
  except UnexpectedAlertPresentException:
      alert = self.driver.switch_to_alert()
      print alert.text
      alert.send_keys('8080')
      alert.dismiss()
  </code></pre>
  
  <p>The <code>UnexpectedAlertPresentException</code> <em>is</em> being thrown. However, as soon as it tries to execute <code>print alert.text</code>, I get: </p>
  
  <pre><code>`NoAlertPresentException: Message: u'No alert is present'`.
  </code></pre>
  
  <p>If I remove the print statement, it blows up at <code>alert.send_keys</code> with:</p>
  
  <pre><code>`WebDriverException: Message: u'fxdriver.modals.find_(...) is null'`
  </code></pre>
  
  <p>I don't get it. Isn't the <code>NoAlertPresentException</code> by definition contradicting the <code>UnexpectedAlertPresentException</code> that was thrown and caused the except block to be executed in the first place?</p>
  
  <p>Edit: Also, I can't for the life of me find any documentation on the <code>UnexpectedAlertPresentException</code> in <a href="http://selenium.googlecode.com/svn/trunk/docs/api/py/index.html#documentation">http://selenium.googlecode.com/svn/trunk/docs/api/py/index.html#documentation</a></p>
  
  <p>Edit 2: This is what I have now:</p>
  
  <pre><code>try:
      if button.text == "Run":
          button.click()
  
          alert = self.driver.switch_to_alert()
  
          alert.send_keys('1111')
          alert.dismiss()
  
   except NoAlertPresentException:
       pass
  </code></pre>
  
  <p>However, I'm still seeing this:</p>
  
  <pre><code>WebDriverException: Message: u'fxdriver.modals.find_(...) is null' 
  </code></pre>
  
  <p>on the line <code>alert.send_keys('8080')</code>. I guess I don't understand why <code>switch_to_alert()</code> doesn't throw <code>NoAlertPresent</code> if there isn't an alert...which is what I'm assuming the <code>WebDriverException</code> is indicating.</p>