In java selenium-webdriver package, there is a FluentWait
class:
Each FluentWait instance defines the maximum amount of time to wait for a condition, as well as the frequency with which to check the condition. Furthermore, the user may configure the wait to ignore specific types of exceptions whilst waiting, such as NoSuchElementExceptions when searching for an element on the page.
In other words, it is something more than implicit and explicit wait, gives you more control for waiting for an element. It can be very handy and definitely has use cases.
Is there anything similar in python selenium package, or should I implement it myself?
(I've looked through documentation for Waits - nothing there).
I believe you can do this with Python, however it isn't packaged as simply as a FluentWait class. Some of this was covered in the documentation you provided by not extensively.
The WebDriverWait class has optional arguments for timeout, poll_frequency, and ignored_exceptions. So you could supply it there. Then combine it with an Expected Condition to wait for elements for appear, be clickable, etc... Here is an example:
Obviously you can combine the wait/element into one statement but I figured this way you can see where this is implemented.
iChar's answer covers how to use
WebDriverWait
in Python to do whatFluentWait
does in Java. Some aspects of the question were left unaddressed though:No. As of version 2.42.x of Selenium, there are only two kinds of waits that Selenium implements: implicit and explicit.
FluentWait
is not something additional to these two kinds of wait. It is just an explicit wait.The only thing I can think of that is missing from Python's
WebDriverWait
implementation thatFluentWait
(andWebDriverWait
, by extension) has, is this:[Quoted from this.]
The
WebDriverWait
class in Python is designed in such a way that its configuration values are set once and for all when it is created.FluentWait
allows its configuration to be changed after creation. So a singleFluentWait
object (or anyWebDriverWait
in Java) could be reused to wait for different conditions with different polling frequencies. In Python, you'd have to create a newWebDriverWait
object to use a different polling frequency.So there is something the Python implementation does not provide but I would not consider this significant enough to warrant an implementation.