begin
ie.select_list(:id, "PageSize").select_value("300")
rescue Watir::Exception::UnknownObjectException
aftererrorObj.errorMain(ie,con,country)
retry
rescue Timeout::Error
aftererrorObj.errorMain(ie,con,country)
retry
end
my ruby code is handling exception in this way.Is this right way to handle exception? will it work?
If you're just looking to rescue the script in case the object has not loaded yet due to AJAX or slow response time, something like this might be more appropriate:
Watir::Wait.until(60) { ie.select_list(:id, "PageSize").exists? }
OR
ie.select_list(:id, "PageSize").when_present.select_value("300)
If just want to catch multiple types of exceptions in the same rescue, combine them as comma separated list:
begin
ie.select_list(:id, "PageSize").select_value("300")
rescue Watir::Exception::UnknownObjectException, Timeout::Error
aftererrorObj.errorMain(ie,con,country)
retry
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.