wait
The command to execute a method or function as a condition to wait for.
There are two types of Wait objects:
WebDriverWait (default)
Directly from Selenium
Returns
WebElement
andList[WebElement]
PyleniumWait
Returns
Element
andElements
Has a built-in
.sleep()
method
wait.until(condition)
is the most common use of Wait and allows you to wait until the condition returns a non-False value.
However, both Waits require the condition to use a WebDriver. In the example below, we can pass in a lambda (aka anonymous function) where x
is the WebDriver.
Syntax
Usage
The usages are almost identical between the Wait objects, but you need to identify why you need to use a Wait in the first place. Pylenium does a lot of waiting for you automatically, but not for everything.
Remember, the biggest difference is what is returned: WebElement
vs Element
Good framework and test design includes waiting for the right things. This is called Synchronization
WebDriverWait
This is the default Wait object. This will return WebElement, so you won't have Pylenium's Element commands like .hover()
- that is what PyleniumWait is for.
Using the defaults
Using custom
timeout
Using
ignored_exceptions
By default, the only exception that is ignored is the NoSuchElementException
. You can change this by adding a list of Exceptions that you want your condition to ignore.
Combine arguments
PyleniumWait
If you want to return Pylenium objects like Element
and Elements
, then set use_py=True
.
Otherwise, it works the same way as WebDriverWait.
PyleniumWait also includes a
.sleep()
command
Expected Conditions
Expected Conditions are a list of pre-built conditions that you can use in your Waits and can be used in either WebDriverWait or PyleniumWait to replace the lambda functions in the examples above.
Yields
Any - Whatever the non-False value of the condition is
Raises
TimeoutException
if the condition is not met within the timeout timeDepending on the condition, it would raise other Exceptions. If you know which ones are expected, you can include them in the
ignored_exceptions
as an argument.
Last updated