DEV Community

Cover image for πŸ”₯πŸ”₯ How to Use WebdriverWait in Selenium?
Pramod Dutta
Pramod Dutta

Posted on • Updated on

πŸ”₯πŸ”₯ How to Use WebdriverWait in Selenium?

βœ… Join us - https://sendfox.com/thetestingacademy
βœ… Master API Testing - https://learnapitesting.com.

In this video, We are going to learn How to Use WebDriver wait in Selenium?

 WebdriverWait in Selenium

πŸš€ Day 30 Task : WebdriverWait in Selenium
πŸš€ All Task List : https://scrolltest.com/automation/task
πŸš€ Watch Full Playlist : https://apitesting.co/30days

βœ… What is WebDriver Wait?
It is applied on certain element with defined expected condition and time.
It is Type of Explicit Wait.
Explicit Wait is code you define to wait for a certain condition to occur before proceeding further in the code.
wait is only applied to the specified element
It can also throw exception when element is not found.

βœ…Types of Explicit Wait in Selenium?

  1. WebDriverWait -
  • alertIsPresent()
    • elementSelectionStateToBe()
    • elementToBeClickable() - elementToBeSelected()
    • frameToBeAvaliableAndSwitchToIt()
    • invisibilityOfTheElementLocated()
    • invisibilityOfElementWithText()
    • presenceOfAllElementsLocatedBy()
    • presenceOfElementLocated()
    • textToBePresentInElement()
    • textToBePresentInElementLocated()
    • textToBePresentInElementValue()
    • titles()
    • titleContains()
    • visibilityOf()
    • visibilityOfAllElements()
    • visibilityOfAllElementsLocatedBy() visibilityOfElementLocated()
  //WebDriverWait wait = new WebDriverWait(WebDriverRefrence,TimeOut);
  WebDriverWait wait = new WebDriverWait (driver, 10);
 wait.until(ExpectedConditions.VisibilityofElementLocated(id(β€œbtn-make-appointment”)));
  1. FluentWait.
Sample usage:

   // Waiting 30 seconds for an element to be present on the page, checking
   // for its presence once every 5 seconds.
   Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
       .withTimeout(30, SECONDS)
       .pollingEvery(5, SECONDS)
       .ignoring(NoSuchElementException.class);

   WebElement foo = wait.until(new Function<WebDriver, WebElement>() {
     public WebElement apply(WebDriver driver) {
       return driver.findElement(By.id("foo"));
     }
   });

--
Be sure to subscribe for more videos like this!

 TheTestingAcademy

Top comments (0)