title: how to handle javascript alerts in selenium using python
body: <p>So I there is this button I want to click and if it's the first time you've clicked it. A javascript alert popup will appear. I've been using firebug and just can't find where that javascript is located and I've tried </p>
  
  <pre><code>if EC.alert_is_present:
          driver.switch_to_alert().accept()
  else:
      print("no alert")
  </code></pre>
  
  <p>the above code works if there is an alert box but will throw an error if there is none. even though there is an else statement I've even tried </p>
  
  <pre><code>   if EC.alert_is_present:
              driver.switch_to_alert().accept()
     elif not EC.alert_is_present:
                 print("no alert")
  </code></pre>
  
  <p>it throws me this error</p>
  
  <pre><code>selenium.common.exceptions.NoAlertPresentException: Message: No alert is present
  </code></pre>
  
  <p>how do we get around this?</p>