I've created an instance of Watir::Browser
with chrome set as the browser.
b = Watir::Browser.new :chrome
If I manually close an alert and then try to refresh the page using
b.refresh
the following error is thrown:
Selenium::WebDriver::Error::UnhandledAlertError: unexpected alert open
(Session info: chrome=28.0.1500.95)
(Driver info: chromedriver=2.2,platform=Windows NT 6.1 x86_64)
from C:/ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.35.0/lib/selenium/webdriver/remote/response.rb:51:in assert_ok'
from C:/ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.35.0/lib/selenium/webdriver/remote/response.rb:15:in initialize'
from C:/ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.35.0/lib/selenium/webdriver/remote/http/common.rb:59:in new'
from C:/ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.35.0/lib/selenium/webdriver/remote/http/common.rb:59:in create_response'
from C:/ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.35.0/lib/selenium/webdriver/remote/http/default.rb:66:in request'
from C:/ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.35.0/lib/selenium/webdriver/remote/http/common.rb:40:in call'
from C:/ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.35.0/lib/selenium/webdriver/remote/bridge.rb:634:in raw_execute'
from C:/ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.35.0/lib/selenium/webdriver/remote/bridge.rb:612:in execute'
from C:/ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.35.0/lib/selenium/webdriver/remote/bridge.rb:210:in refresh'
from C:/ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.35.0/lib/selenium/webdriver/common/navigation.rb:38:in refresh'
from C:/ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.4/lib/watir-webdriver/browser.rb:201:in refresh'
When I call b.alert.exists?
it returns true
.
I tried looking at using b.alert.initialize
to reset the state of the alert but it throwns an exception.
Is there a way to completely reset the state of the browser object?
I was facing this problem too:
But I am successfully get rid of it by putting it in a begin-rescue
block.
Here is how:
begin
# put line of code which triggers alert on page
rescue Selenium::WebDriver::Error::UnhandledAlertError
@browser.alert.ok
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With