Create a gist now

Instantly share code, notes, and snippets.

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