Reputation: 89
After clicking a button, a new Windows alert opens. I tried to use this code:
browser.button(:name => 'OpProvisionalCreate').click
browser.execute_script("window.confirm = function() {return true}")
browser.window(:title => "Message from webpage").use do
browser.button(:id => "close").click
end
But I am getting an error message:
:in `<top (required)>': undefined method `window' for #<Watir::IE:0x1a76990> (NoMethodError)
Upvotes: 2
Views: 2297
Reputation: 1905
You are probably using an older version of watir-classic. Browser#window
method was added in watir-classic 3.0.0. But closing a JavaScript popup should be done with the help of Alert API:
# this will open the popup? Use #click_no_wait in that case.
browser.button(:name => 'OpProvisionalCreate').click_no_wait
# close the popup
browser.alert.close
Read more from the Container and Alert documentation. If you want to use the Alert API mentioned above, then you need to use watir-classic 3.1.0 or newer.
Upvotes: 3