我需要检查一个元素是否从页面中消失,以下代码对我来说没问题:
def checkavailabilitycheck
outtime = 10
wait = Selenium::WebDriver::Wait.new(:timeout => outtime)
begin
wait.until { $browser.find_elements(:css, 'img[src="preloader5.gif"]').size == 7 }
puts "Check succeeded"
rescue Selenium::WebDriver::Error::TimeOutError
puts "Check aborted, canceld after " + outtime.to_s + " seconds"
end
end
现在我想添加类似
的内容puts "Check succeeded after " + wait.tookWhatEverTime + " seconds"
知道怎么做吗?
答案 0 :(得分:2)
你可以这样做:
w1 = Time.now
begin
wait.until { $browser.find_elements(:css, 'img[src="preloader5.gif"]').size == 7 }
puts "Check succeeded"
rescue Selenium::WebDriver::Error::TimeOutError
puts "Check aborted, canceld after " + outtime.to_s + " seconds"
end
w2 = Time.now
puts "Check succeeded after " + (w2 - w1) + " seconds"
答案 1 :(得分:0)
一种方法是在进入等待之前保存当前时间。从等待中抽出时间。
两者的区别在于等待时间。
以下是逻辑
的伪代码timeBeforeEnteringThewait = Time.now
//Code for the wait
// after the wait is finished...
timeAfterThewait = Time.now
elapsedTime = timeAfterThewait - timeBeforeEnteringThewait