Syntax error What are the different types of wait available in Selenium?

What are the different types of wait available in Selenium?



The different types wait available in Selenium are listed below −

  • Implicit wait

    This is one of dynamic waits in Selenium with the Syntax as −

    driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);
  • Explicit wait

    This is one of dynamic waits in Selenium with the Syntax as −

    WebDriverWait w = new WebDriverWait(driver,);
    w.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("<<xpath expression>>")));
  • Fluent wait

    This is one of dynamic waits in Selenium with the Syntax as −

    Wait<WebDriver> w = new
    FluentWait<WebDriver>(driver).withTimeout(Duration.ofSeconds(30))
    .pollingEvery(Duration.ofSeconds(3)).ignoring(NoSuchElementException.class);
  • Static wait

This is used to pause the execution for a specified amount of time.

Example

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
import java.util.List;
public class ThreadWait {
   public static void main(String[] args) throws InterruptedException {
      long start = System.currentTimeMillis();
      // pause the execution 1 seconds
      Thread.sleep(1000);
      long startaftersleep = System.currentTimeMillis();
      System.out.println("Sleep time in ms = "+ startaftersleep - start);
   }
}
Updated on: 2020-06-10T13:51:04+05:30

794 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements