簡體   English   中英

如何使用Watir :: Waiter :: wait_until強制Chrome等待?

[英]How do I use Watir::Waiter::wait_until to force Chrome to wait?

我試圖告訴我的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::Waiter是IE專用課嗎? 或者我做錯了什么, sleep 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”在這里表示“元素既存在又可見”。

您也可以使用browser.it設置超時,等待700秒,就像這樣。

client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 700 # seconds � default is 60 second
ie=Watir::Browser.new:firefox, :http_client => client

幾周前我遇到了同樣的問題。 關鍵是Watir :: Wait.until {}僅等待加載主頁面(主要在Firefox上測試)。 如果您有一些JavaScript代碼加載其他組件,則不會等待這些代碼。

因此,唯一的解決方案是pick和element並明確等待它出現(使用方法2和3)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM