Class WebDriverWait

java.lang.Object
org.openqa.selenium.support.ui.WebDriverWait
All Implemented Interfaces:
Wait<org.openqa.selenium.WebDriver>

public class WebDriverWait extends Object implements Wait<org.openqa.selenium.WebDriver>
An implementation of the Wait interface that makes use of WebDriver. The expected usage is in conjunction with the ExpectedCondition interface.

Because waiting for elements to appear on a page is such a common use-case, this class will silently swallow NotFoundException whilst waiting.

  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    WebDriverWait(org.openqa.selenium.support.ui.Clock clock, org.openqa.selenium.WebDriver driver, long timeOutInSeconds, long sleepTimeOut)
     
     
    WebDriverWait(org.openqa.selenium.WebDriver driver, long timeOutInSeconds)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    throwTimeoutException(String message, Exception lastException)
    Override this method to throw an exception that is idiomatic for a given test infrastructure.
    <T> T
    until(com.google.common.base.Function<org.openqa.selenium.WebDriver,T> isTrue)
    Implementations should wait until the condition evaluates to a value that is neither null nor false.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • WebDriverWait

      public WebDriverWait(org.openqa.selenium.WebDriver driver, long timeOutInSeconds)
      Parameters:
      driver - The WebDriver instance to pass to the expected conditions
      timeOutInSeconds - The timeout in seconds when an expectation is called
    • WebDriverWait

      protected WebDriverWait(org.openqa.selenium.support.ui.Clock clock, org.openqa.selenium.WebDriver driver, long timeOutInSeconds, long sleepTimeOut)
      Parameters:
      clock - The clock to use when measuring the timeout
      driver - The WebDriver instance to pass to the expected conditions
      timeOutInSeconds - The timeout in seconds when an expectation is
      sleepTimeOut - The timeout used whilst sleeping. Defaults to 500ms called
  • Method Details

    • until

      public <T> T until(com.google.common.base.Function<org.openqa.selenium.WebDriver,T> isTrue)
      Description copied from interface: Wait
      Implementations should wait until the condition evaluates to a value that is neither null nor false. Because of this contract, the return type must not be Void.

      If the condition does not become true within a certain time (as defined by the implementing class), this method will throw a non-specified Throwable. This is so that an implementor may throw whatever is idiomatic for a given test infrastructure (e.g. JUnit4 would throw AssertionError.

      Specified by:
      until in interface Wait<org.openqa.selenium.WebDriver>
      Type Parameters:
      T - the return type of the method, which must not be Void
      Parameters:
      isTrue - the parameter to pass to the ExpectedCondition
    • throwTimeoutException

      protected void throwTimeoutException(String message, Exception lastException)
      Override this method to throw an exception that is idiomatic for a given test infrastructure. E.g. JUnit4 should throw an AssertionError