selenium.webdriver.support.wait

Classes

WebDriverWait(driver, timeout[, ...])

Constructor, takes a WebDriver instance and timeout in seconds.

class selenium.webdriver.support.wait.WebDriverWait(driver: D, timeout: float, poll_frequency: float = 0.5, ignored_exceptions: Iterable[Type[Exception]] | None = None)[source]

Constructor, takes a WebDriver instance and timeout in seconds.

Args:
  • driver - Instance of WebDriver (Ie, Firefox, Chrome or Remote) or a WebElement

  • timeout - Number of seconds before timing out

  • poll_frequency - sleep interval between calls By default, it is 0.5 second.

  • ignored_exceptions - iterable structure of exception classes ignored during calls. By default, it contains NoSuchElementException only.

Example:

from selenium.webdriver.support.wait import WebDriverWait 

element = WebDriverWait(driver, 10).until(lambda x: x.find_element(By.ID, "someId")) 

is_disappeared = WebDriverWait(driver, 30, 1, (ElementNotVisibleException)).\ 

            until_not(lambda x: x.find_element(By.ID, "someId").is_displayed())
until(method: Callable[[D], Literal[False] | T], message: str = '') T[source]

Calls the method provided with the driver as an argument until the return value does not evaluate to False.

Parameters:
  • method – callable(WebDriver)

  • message – optional message for TimeoutException

Returns:

the result of the last call to method

Raises:

selenium.common.exceptions.TimeoutException if timeout occurs

until_not(method: Callable[[D], T], message: str = '') T | Literal[True][source]

Calls the method provided with the driver as an argument until the return value evaluates to False.

Parameters:
  • method – callable(WebDriver)

  • message – optional message for TimeoutException

Returns:

the result of the last call to method, or True if method has raised one of the ignored exceptions

Raises:

selenium.common.exceptions.TimeoutException if timeout occurs