Different Wait Methods in Selenium WebDriver

Following are the different types of wait methods available in Selenium WebDriver:

Implicit Wait:

WebDriver waits for a certain duration of time until all the elements on the page are loaded. This can be useful when certain elements on the webpage are not available immediately and need some time to load.

driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);

Explicit Wait:

WebDriver will wait for a specific element on the page until the given condition is satisfied. This can be useful if one of the element take longer time to load compared to other elements on the page.

driver.findElement(By.xpath("//a[text()=' Sign Up Here']")).click();
WebDriverWait wait = new WebDriverWait(driver,30);
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("firstName"))).sendKeys("qascript");

Fluent Wait:

It tells the webdriver to wait for a condition, as well as the frequency with which to check the condition.

Wait<WebDriver> wait1 = new FluentWait<>(driver)
.withTimeout(Duration.ofSeconds(30))
.pollingEvery(Duration.ofSeconds(5))
.ignoring(NoSuchElementException.class);

WebElement element = wait1.until(new Function<WebDriver, WebElement>() {
@Override
public WebElement apply(WebDriver driver) {
return driver.findElement(By.id("firstName"));
}
});
element.sendKeys("qascript");

PageLoad Timeout:

Sets the amount of time to wait for a page-load to complete before throwing an error.

driver.manage().timeouts().pageLoadTimeout(30,TimeUnit.SECONDS);

SetScript Timeout:

Sets the amount of time to wait for an asynchronous script to finish execution before throwing an error.

driver.manage().timeouts().setScriptTimeout(30,TimeUnit.SECONDS);

 

Share

Bijan Patel

Founder & Creator of QAScript | 12+ years of IT Experience | Full Stack Automation Engineer | Blogger | Trainer

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!