Different Wait Methods in Selenium WebDriver

Learn about the different wait methods in Selenium WebDriver

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);


Bijan Patel
Bijan Patel
Full Stack Test Automation Expert | Selenium Framework Developer | Certified Tosca Automation Specialist | Postman | DevOps | AWS | IC Agile Certified | Trainer | Youtuber | Blogger|

Launch your GraphyLaunch your Graphy
100K+ creators trust Graphy to teach online
𝕏
QASCRIPT 2024 Privacy policy Terms of use Contact us Refund policy