Reputation: 11
I am trying to create an automation script for a website using Ruby with Watir.
I ran into a situation where I have to choose 'Yes' or 'No' in an alert box. The problem is that I am not able to identify the alert box as a component of the page so that I can obtain its identifier and use it to select an option.
I found some information how to create an alert box, but I need to navigate through one. Can anyone help me out?
Upvotes: 1
Views: 1175
Reputation: 1989
You can use these clean watir calls:
See Official Framework Documentation for more info.
Upvotes: 0
Reputation: 5560
The approach suggested by Austin Taylor may work fine, but I think that for a more general solution you need to deal with Popups at a OS level as Chuck suggests.
If anyone reaches this page seeking this sort of answer there are different solutions listed here: http://wiki.openqa.org/display/WTR/JavaScript+Pop+Ups
Upvotes: 1
Reputation: 5477
It sounds like you have a confirm
box if you can choose two options ("OK" or "Cancel"). If you want to simulate clicking "OK", you have to put something like this before you trigger the confirm.
# return true for confirm to simulate clicking OK
b.execute_script("window.confirm = function() {return true}")
If you just have an alert
with a single "OK" button, do this.
# don't return anything for alert
b.execute_script("window.alert = function() {}")
See this page for more examples.
Upvotes: 3