title: Handling alerts using if/else in Java
body: <p>How to handle the <strong>alerts</strong> using <strong>if/else</strong> commands? If alerts comes up do <strong>accept/dismiss</strong>, if not <strong>proceed further</strong>. I was trying with below code but an error at <strong>(r==true)</strong> says incompatible type. </p>
  
  <pre><code>bool r = driver.findElement(By.xpath("//div[contains(text(),'javax.baja.sys.ActionInvokeException')]"));
  if (r = true) {
      driver.switchTo().alert().accept();
  } else {
      Actions click2 = new Actions(driver);
      WebElement dclick2 = driver.findElement(By.xpath(".//span[text()='Bluemix_As_Device']"));
      click2.moveToElement(dclick2).doubleClick().build().perform();
  }
  </code></pre>