Table of Contents

Class DefaultWait<T>

Namespace
OpenQA.Selenium.Support.UI
Assembly
WebDriver.dll

An implementation of the IWait<T> interface that may have its timeout and polling interval configured on the fly.

public class DefaultWait<T> : IWait<T>

Type Parameters

T

The type of object on which the wait it to be applied.

Inheritance
DefaultWait<T>
Implements
Derived
Inherited Members

Constructors

DefaultWait(T)

Initializes a new instance of the DefaultWait<T> class.

public DefaultWait(T input)

Parameters

input T

The input value to pass to the evaluated conditions.

DefaultWait(T, IClock)

Initializes a new instance of the DefaultWait<T> class.

public DefaultWait(T input, IClock clock)

Parameters

input T

The input value to pass to the evaluated conditions.

clock IClock

The clock to use when measuring the timeout.

Exceptions

ArgumentNullException

If clock or input are null.

Properties

Message

Gets or sets the message to be displayed when time expires.

public string Message { get; set; }

Property Value

string

PollingInterval

Gets or sets how often the condition should be evaluated. The default timeout is 500 milliseconds.

public TimeSpan PollingInterval { get; set; }

Property Value

TimeSpan

Timeout

Gets or sets how long to wait for the evaluated condition to be true. The default timeout is 500 milliseconds.

public TimeSpan Timeout { get; set; }

Property Value

TimeSpan

Methods

IgnoreExceptionTypes(params Type[])

Configures this instance to ignore specific types of exceptions while waiting for a condition. Any exceptions not whitelisted will be allowed to propagate, terminating the wait.

public void IgnoreExceptionTypes(params Type[] exceptionTypes)

Parameters

exceptionTypes Type[]

The types of exceptions to ignore.

ThrowTimeoutException(string, Exception?)

Throws a WebDriverTimeoutException with the given message.

protected virtual void ThrowTimeoutException(string exceptionMessage, Exception? lastException)

Parameters

exceptionMessage string

The message of the exception.

lastException Exception

The last exception thrown by the condition.

Remarks

This method may be overridden to throw an exception that is idiomatic for a particular test infrastructure.

Until<TResult>(Func<T, TResult?>)

Repeatedly applies this instance's input value to the given function until one of the following occurs:

  • the function returns neither null nor false
  • the function throws an exception that is not in the list of ignored exception types
  • the timeout expires
public virtual TResult Until<TResult>(Func<T, TResult?> condition)

Parameters

condition Func<T, TResult>

A delegate taking an object of type T as its parameter, and returning a TResult.

Returns

TResult

The delegate's return value.

Type Parameters

TResult

The delegate's expected return type.

Until<TResult>(Func<T, TResult?>, CancellationToken)

Repeatedly applies this instance's input value to the given function until one of the following occurs:

  • the function returns neither null nor false
  • the function throws an exception that is not in the list of ignored exception types
  • the timeout expires
public virtual TResult Until<TResult>(Func<T, TResult?> condition, CancellationToken token)

Parameters

condition Func<T, TResult>

A delegate taking an object of type T as its parameter, and returning a TResult.

token CancellationToken

A cancellation token that can be used to cancel the wait.

Returns

TResult

The delegate's return value.

Type Parameters

TResult

The delegate's expected return type.