我创建了Watir::Browser
的实例,并将chrome设置为浏览器。
b = Watir::Browser.new :chrome
如果我手动关闭提醒,然后尝试使用
刷新页面b.refresh
抛出以下错误:
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'
当我致电b.alert.exists?
时,它会返回true
。
我尝试使用b.alert.initialize
来重置警报的状态,但它会抛出异常。
有没有办法完全重置浏览器对象的状态?
答案 0 :(得分:7)
我也遇到了这个问题:
但是我把它放在begin-rescue
区块中成功摆脱它。
以下是:
begin
# put line of code which triggers alert on page
rescue Selenium::WebDriver::Error::UnhandledAlertError
@browser.alert.ok
end