Saturday, April 12, 2014

Wait for the element Present in Selenium WebDriver(Explicit Wait)



In General , in Slenium Webdriver we have  two types of wait commands are available. implicit wait and explicit wait. 

 implicit wait :
It's global setting applicable for all elements and if element appear before specified time than script will start executing otherwise script will throw NoSuchElementException.  

    Thread.sleep() - It will sleep time for script, not good way to use in script as it's sleep without condition.

driver.manage().timeouts().implicitlyWait(120,TimeUnit.SECONDS)


explicit wait:  Wait for the element to be present

WebDriverWait explicit=new WebDriverWait(driver, 10);   // 10 in secs 

explicit.until(ExpectedConditions.visibilityOfElementLocated(By.id("element id"))).click();