本文介绍了Java中的Java FluentWait的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在java selenium-webdriver包中,有一个 class:

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

换句话说,它不仅仅是,为您提供更多控制等待元素。它可以非常方便,绝对有用例。

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).

推荐答案

我相信你可以用Python做到这一点,但它没有打包成只是作为一个FluentWait类。其中一些内容未在您提供的文档中详细介绍。

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.

WebDriverWait类具有timeout,poll_frequency和ignored_exceptions的可选参数。所以你可以在那里供应。然后将它与预期条件结合起来等待元素出现,可点击等等......这是一个例子:

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:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import *

driver = webdriver.Firefox()
# Load some webpage
wait = WebDriverWait(driver, 10, poll_frequency=1, ignored_exceptions=[ElementNotVisibleException, ElementNotSelectableException])
element = wait.until(EC.element_to_be_clickable((By.XPATH, "//div")))

显然你可以将wait / element合并到一个语句中,但我想通过这种方式你可以看到它的实现位置。

Obviously you can combine the wait/element into one statement but I figured this way you can see where this is implemented.

这篇关于Java中的Java FluentWait的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 13:22