Tuesday, December 16, 2014


If the WebDriver does not get web element then the WebDriver will wait for specified time and WebDriver will not try to search the element during the specified time. Once the specified time is over, WebDriver will start searching the web element only one time before throwing the exception.





Selenium Implicit Wait Example


import java.util.concurrent.TimeUnit;

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Training {
 static WebDriver driver;

 public static void main(String[] args) throws InterruptedException {

  WebDriver driver = new FirefoxDriver();
  driver.navigate().to(
    "http://www. w3schools. com/js/tryit. asp?filename=tryjs_alert");

  driver.switchTo().frame(0);

  driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
  WebElement element = driver.findElement(By.tagName("button"));
  element.click();

  Alert alert = driver.switchTo().alert();

  System.out.println(alert.getText());
  Thread.sleep(5000);
  alert.accept();
 }

}