我试图告诉我的watir脚本等待ajax注册登录框打开.我正在使用watir-webdriver,并在Chrome中进行测试.如下面(简化的)脚本所述,我无法让wait_until工作.
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 ::服务员是仅IE类吗?或者我做错了什么,睡眠1等待方法工作正常.我是Ruby和watir的新手,我字面上只是昨天拿起来,所以我一半期望这是我的无礼的结果.
如果是相关的,我正在使用mac(OSX v.10.6.5).
解决方法
先做这个:
require "watir-webdriver/wait"
然后尝试这些:
1
Watir::Wait.until { ... }
2
browser.text_field(:id => 'username').when_present.set("name")
3
browser.text_field(:id => 'username').wait_until_present
请注意,这里的“present”表示“元素既存在又可见”.