Skip to content

Instantly share code, notes, and snippets.

@rtacconi
Created September 8, 2010 11:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rtacconi/569969 to your computer and use it in GitHub Desktop.
Save rtacconi/569969 to your computer and use it in GitHub Desktop.
With this code:
browser.link(:text, "Move questions to...").click
browser.alert do
browser.button(:id => "alert").click
end #=> "the alert message"
I get this error:
/Users/riccardotacconi/.rvm/gems/ree-1.8.7-2010.01/gems/watir-webdriver-0.0.9/lib/watir-webdriver/elements/element.rb:182:in `assert_exists': unable to locate element, using {:tag_name=>"button", :id=>"alert"} (Watir::Exception::UnknownObjectException) from /Users/riccardotacconi/.rvm/gems/ree-1.8.7-2010.01/gems/watir-webdriver-0.0.9/lib/watir-webdriver/elements/element.rb:65:in `click' from watir.rb:183 from /Users/riccardotacconi/.rvm/gems/ree-1.8.7-2010.01/gems/watir-webdriver-0.0.9/lib/watir-webdriver/extensions/alerts.rb:24:in `alert' from watir.rb:182
Solved by intercepting the error, but it is a dirty hacks (in .rvm/gems/ree-1.8.7-2010.01/gems/watir-webdriver-0.0.9/lib/watir-webdriver/extensions/alerts.rb:24):
def alert(&blk)
execute_script "window.alert = function(msg) { window.lastAlert = msg; }"
begin
yield
rescue
# nothing
end
execute_script "return window.lastAlert"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment