title: Selenium/WebDriver script gets interrupted by alert - exception "Message: u'Modal dialog present'"
body: <p>I'm fairly new at Python/JS and also automated testing with Selenium/WebDriver, but I have made some progress!</p>
  
  <p>Now I'm stuck at one point and it's really frustrating.</p>
  
  <p>The website I am testing sells products. I managed to make my script navigate randomly and get to the payment page, fill in dummy data, submit data by using:</p>
  
  <pre><code>browser.execute_script("document.Form.submit(); return true;")
  browser.execute_script("processPayment(); return true;")
  </code></pre>
  
  <p>Usually, there is a Pay now button and clicking that element results in the same exception and there was no way for me to click OK/Cancel on it via WebDriver (no WebElement), but I figured out that executing this JS code I can get past it. My newly loaded page (after submitting data and confirming the posting of it) with a confirmation and all correct data loads, but the Python script is interrupted and I can't continue the test.</p>
  
  <p>Is there a workaround for this? What I want it to do is to ignore that modal dialog, wait for the next confirmation page to load and then continue locating elements, printing their values, storing them etc.</p>
  
  <p>Tried using:</p>
  
  <pre><code>wait = ui.WebDriverWait(browser,10)
  wait.until(lambda browser: browser.title.lower().startswith('Your Receipt'))
  print(browser.title)
  </code></pre>
  
  <p>but the script gets interrupted. Sorry if this has been answered, but I couldn't find it, and also I am a newbie!</p>
  
  <p>Thanks in advance!</p>
  
  <p>EDIT:</p>
  
  <p>Did it! In my case what worked is I just modified my code a little</p>
  
  <pre><code>browser.execute_script("document.roomBookingForm.submit(); return true;")
  alert = browser.switch_to_alert()
  alert.dismiss()
  browser.execute_script("processPayment(); return true;")
  </code></pre>
  
  <p>Note for newbies that you will need to import Alert.</p>
  
  <pre><code>from selenium.webdriver.common.alert import Alert
  </code></pre>