title: Facing error as Expected condition failed: waiting for alert to be present (tried for 5 second(s) with 500 milliseconds interval)
body: <p>When condition falls it goes to else, but when it is true not going in if</p>
  
  <pre><code>try {
      //WebDriverWait wait = new WebDriverWait(driver, 5);
  
      if(wait.until(ExpectedConditions.alertIsPresent()) == null) {
          System.out.println("alert was not present")
          (wait.until(ExpectedConditions.elementToBeClickable(By.xpath("/html/body/div[2]/div/div/div[2]/button[2]"))).click();
          Confirmation.click();
      }
      else {
          String Recipemessage = driver.switchTo().alert().getText();
          System.out.println(Recipemessage);
  
          if(Recipemessage.equals(alertmessage2) || Recipemessage.equals(alertmessage4) ) {
  
              Thread.sleep(3000);
  
              driver.switchTo().alert().accept();
              break;
          }
      }
  } catch(Exception exp7) {
      System.out.println(exp7);
  }
  </code></pre>