Skip to content

Instantly share code, notes, and snippets.

@jarib
Created May 14, 2010 16:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jarib/401361 to your computer and use it in GitHub Desktop.
Save jarib/401361 to your computer and use it in GitHub Desktop.
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