I had a look here: http://wiki.openqa.org/display/WTR/JavaScript+Pop+Ups
Every solution is for IE on Windows. I am using Firefox on Mac. Is there a way to click on OK of a JavaScript alert box?
I had a look here: http://wiki.openqa.org/display/WTR/JavaScript+Pop+Ups
Every solution is for IE on Windows. I am using Firefox on Mac. Is there a way to click on OK of a JavaScript alert box?
Proper handling of alerts and prompts is still being worked on in WebDriver, but a common workaround is to overwrite the window functions using execute_script(), i.e.
browser.execute_script("window.alert = function(msg) { window.lastAlert = msg; }")
browser.button(:id => "trigger-alert").click
browser.execute_script("return window.lastAlert") #=> "the message"
Since I'd like to avoid a bunch of monkey patches floating around (a common problem in the Watir community), I've added some helper methods as an optional require - after the next release you should be able to do:
require "watir-webdriver/extensions/alerts"
browser.alert do
browser.button(:id => "alert").click
end #=> "the alert message"
browser.confirm(true) do
browser.button(:id => "confirm").click
end #=> "the confirm message"
browser.prompt("returned value") do
browser.button(:id => "prompt").click
end #=> { :message => "foo", :default => "bar" }
Note that this is temporary and the API may be removed in the future when the issue is resolved in WebDriver.
I know that the iMacros for Firefox addon can click these alert boxes. Maybe you can combine it with our setup?