Watir Webdriver - Exception While Handling Safari Alert

Recently, I decided to work on an automation script to help me book volleyball court in Singapore after reading this article. Not bad for a weekend project ;)

One of the problems I encountered was to handle a javascript triggered alert. So, normally we are supposed to use the following code to handle them:

browser.alert.ok // simulate clicking the ok button
browser.alert.cancel // simulate clicking the cancel button

However, I encountered a weird UnhandledAlertError on Safari. After some research, I realised that because of the way the Safari Web Driver was built, it wasn't able to handle an alert properly. It'll be better to switch browsers if you need your Watir-Webdriver scripts to be able to handle alerts =/

For me, since it doesn't matter as long as the alert is dismissed, I simply rescue the exception and move on. Took me a while to resolve this though.