Java's FluentWait in Python

前端 未结 4 1608
梦毁少年i
梦毁少年i 2020-11-30 11:37

In java selenium-webdriver package, there is a FluentWait class:

Each FluentWait instance defines the maximum amount of time to wait for a condition

4条回答
  •  一向
    一向 (楼主)
    2020-11-30 12:08

    iChar's answer covers how to use WebDriverWait in Python to do what FluentWait does in Java. Some aspects of the question were left unaddressed though:

    In other words, [FluentWait] is something more than implicit and explicit wait

    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.

    Is there anything similar in python selenium package, or should I implement it myself?

    The only thing I can think of that is missing from Python's WebDriverWait implementation that FluentWait (and WebDriverWait, by extension) has, is this:

    [FluentWait (and, by extension, WebDriverWait)] may have its timeout and polling interval configured on the fly.

    [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 single FluentWait object (or any WebDriverWait in Java) could be reused to wait for different conditions with different polling frequencies. In Python, you'd have to create a new WebDriverWait 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.

提交回复
热议问题