做'some_element'.present?在watir等待少于5秒 [英] making 'some_element'.present? in watir wait for less than 5 secs

查看:530
本文介绍了做'some_element'.present?在watir等待少于5秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何使some_element.present?或some_element.visible?等待不到5秒。因为我认为some_element.present?

How do we make some_element.present? or some_element.visible? wait for less than 5 secs.? Because I think some_element.present? alone will wait for default value of 30 secs before timing out.

感谢

推荐答案

我相信你要问如何缩短超时前的时间长度,默认设置为30秒,请参阅下面的自定义时间。

I believe you are asking how to shorten the length of time before timeout, by default its set to 30 seconds, see below on how to customize that time.

根据 http://watirwebdriver.com/waiting/

显式等待

有四种内置方法可用于使您的等待体验更愉快(并从您的代码中删除那些恶意的sleep语句) / p>

There are four built in methods that you can use to make your waiting experience more pleasant (and remove those evil sleep statements from your code)

Watir::Wait.until { ... }: where you can wait for a block to be true
object.when_present.set: where you can do something when it’s present
object.wait_until_present:; where you just wait until something is present
object.wait_while_present:; where you just wait until something disappears
The default timeout for all these methods is 30 seconds, but your can pass an argument to any of these to increase (or decrease) it as needed.

http://rdoc.info/gems/watir-webdriver/Watir/EventuallyPresent

- (Object) wait_until_present(timeout = nil)

等待元素存在。

示例:

browser.button(:id => 'foo').wait_until_present
Parameters:
timeout (Fixnum) (defaults to: nil) — seconds to wait before timing out

- (Object) wait_while_present(timeout = nil)

元素存在时等待。

例如:

browser.button(:id => 'foo').wait_while_present
Parameters:
timeout (Integer) (defaults to: nil) — seconds to wait before timing out

- (Object) when_present(timeout = nil)

等待元素存在。

示例:

browser.button(:id => 'foo').when_present.click
browser.div(:id => 'bar').when_present { |div| ... }
browser.p(:id => 'baz').when_present(60).text
Parameters:
timeout (Fixnum) (defaults to: nil) — seconds to wait before timing out

这篇关于做'some_element'.present?在watir等待少于5秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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