Skip to content

Instantly share code, notes, and snippets.

@jarib
Created May 14, 2010
Embed
What would you like to do?
selenium-webdriver wait
require "rubygems"
require "selenium-webdriver"
def wait(timeout = 10, &blk)
end_time = Time.now + timeout
until Time.now >= end_time
begin
return yield
rescue Selenium::WebDriver::Error::NoSuchElementError
end
sleep 0.5
end
raise "timed out"
end
driver = Selenium::WebDriver.for :firefox
driver.get "http://google.com"
element = wait(2) { driver.find_element(:name => "foo") }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment