title: WebDriver - How to verify if an alert is present?
body: <p>In selenium2 (Webdriver)How to verify if an alert is present? and continue doing something if its not present!!!</p>
  
  <p>I am doing this:</p>
  
  <pre><code>driver.findElement(By.id("btn_may_or_maynot_showalert")).click();
  WebDriverWait wait = new WebDriverWait(driver, 2);
  try{
      wait.until(ExpectedConditions.alertIsPresent());
      Alert alert = driver.switchTo().alert();
      alert.accept();
  }
  catch (Exception e){
      System.out.println("No alert");
  }
  driver.findElement(By.id("Cont_doing_something")).click();
  </code></pre>
  
  <p>This works fine But is there a better way?</p>