如何使用 Watir::Waiter::wait_until 强制 Chrome 等待? [英] How do I use Watir::Waiter::wait_until to force Chrome to wait?

查看:45
本文介绍了如何使用 Watir::Waiter::wait_until 强制 Chrome 等待?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图告诉我的 watir 脚本等待一个注入了 ajax 的登录框打开.我正在使用 watir-webdriver,并在 Chrome 中进行测试.我无法让 wait_until 工作,如以下(简化)脚本中所述.

I'm trying to tell my watir script to wait for an ajax-injected login box to open up. I am using watir-webdriver, and testing in Chrome. I cannot get wait_until to work, as commented in the below (simplified) script.

require "rubygems"
require "watir-webdriver"
b = Watir::Browser.new(:chrome)
site = "www.example.com"
b.goto site

puts "Click on Sign In button"
b.link(:id, 'btnLogin').click

puts "Waiting for the username/password dialog to show up"

# Below line does *not* work
# Throws this error: "uninitialized constant Watir::Waiter (NameError)" 
Watir::Waiter::wait_until { b.text_field(:id, 'username').exists? }

# Below line does *not* work
# Throws this error: "undefined method `wait_until' for main:Object (NoMethodError)" 
wait_until { b.text_field(:id, 'username').exists? }

# Below line *does* work, but I don't want to use it.
sleep 1 until b.text_field(:id, 'username').exists?

Watir::Waiter 是一个仅限 IE 的类吗?或者我做错了什么,sleep 1 等待方法工作得很好.我是 Ruby 和 watir 的新手,我昨天才刚拿起这个,所以我有一半希望这是我的笨拙的结果.

Is Watir::Waiter an IE-only class? Or what am I doing wrong, the sleep 1 wait method works just fine. I am new to Ruby and watir, I literally just picked this up yesterday so I'm half expecting this to be a result of my noobaciousness.

如果相关,我正在使用 mac(OSX v. 10.6.5).

In case it is relevant, I am working on a mac (OSX v. 10.6.5).

推荐答案

先做这个:

require "watir-webdriver/wait"

然后试试这些:

Watir::Wait.until { ... }

2

browser.text_field(:id => 'username').when_present.set("name")

3

browser.text_field(:id => 'username').wait_until_present

注意这里的present"是指元素既存在又可见".

Note that "present" here means "the element both exists and is visible".

这篇关于如何使用 Watir::Waiter::wait_until 强制 Chrome 等待?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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