如果我收到错误,例如......
Modal dialog present: "The data could not be loaded." (Selenium::WebDriver
::Error::UnhandledAlertError)
错误扩展
And save the product.
# features/step_definitions/setup_sd.rb:35
Modal dialog present: "The data could not be loaded."(Selenium::WebDriver
::Error::UnhandledAlertError)
[remote server] file:///C:/Users/blah/AppData/Local/Temp/webdriver-profi
le20161219-65588-1gtvf51/extensions/fxdriver@googlecode.com/components/command-p
rocessor.js:12770:in `nsCommandProcessor.prototype.execute'
[remote server] file:///C:/Users/blah/AppData/Local/Temp/webdriver-profile20161219-65588-1gtvf51/extensions/fxdriver@googlecode.com/components/driver-component.js:9576:in `Dispatcher.executeAs/<'
[remote server] file:///C:/Users/blah/AppData/Local/Temp/webdriver-profile20161219-65588-1gtvf51/extensions/fxdriver@googlecode.com/components/driver-component.js:9723:in `Resource.prototype.handle'
[remote server] file:///C:/Users/blah/AppData/Local/Temp/webdriver-profile20161219-65588-1gtvf51/extensions/fxdriver@googlecode.com/components/driver-component.js:9670:in `Dispatcher.prototype.dispatch'
[remote server] file:///C:/Users/blah/AppData/Local/Temp/webdriver-profile20161219-65588-1gtvf51/extensions/fxdriver@googlecode.com/components/driver-component.js:12544:in `WebDriverServer/<.handle'
[remote server] file:///C:/Users/blah/AppData/Local/Temp/webdriver-profile20161219-65588-1gtvf51/extensions/fxdriver@googlecode.com/components/httpd.js:2054:in `createHandlerFunc/<'
[remote server] file:///C:/Users/blah/AppData/Local/Temp/webdriver-profile20161219-65588-1gtvf51/extensions/fxdriver@googlecode.com/components/httpd.js:2387:in `ServerHandler.prototype.handleResponse'
[remote server] file:///C:/Users/blah/AppData/Local/Temp/webdriver-profile20161219-65588-1gtvf51/extensions/fxdriver@googlecode.com/components/httpd.js:1223:in `Connection.prototype.process'
[remote server] file:///C:/Users/blah/AppData/Local/Temp/webdriver-profile20161219-65588-1gtvf51/extensions/fxdriver@googlecode.com/components/httpd.js:1677:in `RequestReader.prototype._handleResponse'
[remote server] file:///C:/Users/blah/AppData/Local/Temp/webdriver-profile20161219-65588-1gtvf51/extensions/fxdriver@googlecode.com/components/httpd.js:1525:in `RequestReader.prototype._processBody'
[remote server] file:///C:/Users/blah/AppData/Local/Temp/webdriver-profile20161219-65588-1gtvf51/extensions/fxdriver@googlecode.com/components/httpd.js:1393:in `RequestReader.prototype.onInputStreamReady'
[remote server] resource://gre/components/nsPrompter.js:394:in `openModalWindow'
[remote server] resource://gre/components/nsPrompter.js:491:in `ModalPrompter.prototype.openPrompt'
[remote server] resource://gre/components/nsPrompter.js:543:in `ModalPrompter.prototype.alert'
[remote server] file:///C:/Users/blah/AppData/Local/Temp/webdriver-profile20161219-65588-1gtvf51/extensions/fxdriver@googlecode.com/components/prompt-service.js:4800:in `ObservingAlert.prototype.alert'
[remote server] http://10.20.13.39:17007/ScriptResource.axd?d=OwfU9dJwZwohiTGVGwSmnis5Sz77zh88m4xormA1BrE_-VNmQFnovvsDzNzH0qQCr6JjS2t6QbrSRBO86wKNXm1cO31z7GUAtLwQK7eaJqY5kZhHVmGxOxCJOEbh_mzvIE82nn2eWB69U7ZhzAQgCM43cXTVpLMGGjDVeilur_aPJt6ieH-q_9a1xO06Hhnb0&t=5df05159:1:in `_z19F'
./features/step_definitions/setup_sd.rb:37:in `/^save the product\.$/'
features/product_setup/Setup05_template_var_textbox.feature:8:in `And save the product.'
我可以救出来吗?
When(/^save the product\.$/) do
pf = blah_page.new
within_frame('blah') do
sleep(2)
begin
find(:css, pf.LOC_BTN_SAVE_BLAH).click
#rescue Selenium::WebDriver::Error::UnhandledAlertError #error still raises
rescue #error still raises
page.accept_alert
sleep(0.05)
end
end
end
我已经能够从element_not_found中解救出来,我想知道是否有什么东西可以防止从这种错误类型中解救出来。
有什么想法吗?
答案 0 :(得分:1)
Selenium :: WebDriver :: Error :: UnhandledAlertError绝对可以被拯救,如果你在它被抛出的块的末尾捕获它。根据您使用的浏览器(某些浏览器在引发错误时自动清除)需要在继续之前调用page.accept_alert
来清除警报,否则下一页操作将重新引发相同的错误。< / p>