Skip to content

Instantly share code, notes, and snippets.

@alisterscott
Created August 3, 2011 10:39
Show Gist options
  • Save alisterscott/1122352 to your computer and use it in GitHub Desktop.
Save alisterscott/1122352 to your computer and use it in GitHub Desktop.
methods to locate elements are okay
require 'watir-webdriver'
def search_field browser
browser.text_field(:name => "q")
end
browser = Watir::Browser.new :firefox
begin
browser.goto "http://google.com"
#element = browser.text_field(:name => "q")
p search_field(browser).value # element is now located
browser.refresh # refreshing the page obsoletes the element
begin
p search_field(browser).value
rescue Selenium::WebDriver::Error::ObsoleteElementError
# doesn't get raised
end
# relocating the element works
#element = browser.text_field(:name => "q")
p search_field(browser).value
ensure
browser.close
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment