After some time googling for a simple way to interact with annoying popups. I found a few but couldn’t really solve what I wanted to do. Most articles showed a way to switch to the popup window by using the window name. In my case, the window I was trying to work with didn’t have a name. So I did what was best, dive into the watir-webdriver gem and found a solution. Funny thing is that the code is probably better documented than anywhere else.
The watir-webdriver browser object has an alert method which switches the driver to that window and returns an instance of the Alert class. Nice, half the work is down with is method alone. You can take the return object and call:
Alert#text – returns the text on the alert box
Alert#ok – closes or accepts the prompt
Alert#close – closes or cancels the prompt