wait
The command to execute a method or function as a condition to wait for.
Last updated
The command to execute a method or function as a condition to wait for.
Last updated
Pylenium provides a Should API for , , and objects. This is the recommended way to wait for things in Pylenium.
However, you can use Selenium's ExpectedConditions class or lambdas as shown on the rest of this page.
There are two types of Wait objects:
WebDriverWait (default)
Directly from Selenium
Returns WebElement
and List[WebElement]
PyleniumWait
Returns Element
and Elements
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.
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.
Good framework and test design includes waiting for the right things. This is called Synchronization
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
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 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.
Any - Whatever the non-False value of the condition is
TimeoutException
if the condition is not met within the timeout time
Depending 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.