Implicit Wait: During Implicit wait if the Web Driver cannot find it immediately because of its availability, the WebDriver will wait for mentioned time and it will not try to find the element again during the specified time period. Once the specified time is over, it will try to search the element once again the last time before throwing exception. The default setting is zero. Once we set a time, the Web Driver waits for the period of the WebDriver object instance.
Explicit Wait: There can be instance when a particular element takes more than a minute to load. In that case you definitely not like to set a huge time to Implicit wait, as if you do this your browser will going to wait for the same time for every element.
public void expliciteWait(By by, int timeToWaitInSec) {
WebDriverWait wait = new WebDriverWait(driver, timeToWaitInSec);
wait.until(ExpectedConditions.presenceOfElementLocated(by));
}
public void impliciteWait(int timeToWaitInSec) {
driver.manage().timeouts().implicitlyWait(timeToWaitInSec, TimeUnit.SECONDS);
}
public WebElement getWhenVisible(By locator, int timeout) {
WebElement element = null;
WebDriverWait wait = new WebDriverWait(driver, timeout);
element = wait.until(ExpectedConditions
.visibilityOfElementLocated(locator));
return element;
}
public void clickWhenReady(By locator, int timeout) {
WebElement element = null;
WebDriverWait wait = new WebDriverWait(driver, timeout);
element = wait.until(ExpectedConditions.elementToBeClickable(locator));
element.click();
}
No comments:
Post a Comment