Java中的Java FluentWait [英] Java's FluentWait in Python

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

问题描述

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

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


每个FluentWait实例定义等待
条件的最长时间,以及检查
条件的频率。此外,用户可以配置等待在等待时忽略
特定类型的异常,例如在页面上搜索元素时
NoSuchElementExceptions。

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.

python selenium package 中是否有类似内容,或者我应该我自己实现了吗?

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆