Sometimes when a user is using a web page a pop-up window appears. These requires special attention in watir.
Pop-Up examples:
Security Alerts
Choose File pop-ups
Save As
Login (username/password) panels
Alert boxes
Script prompt/textbox
Confirmation Boxes (ok/cancel)
Code to Handle pop ups
require 'watir'
require 'watir/dialog'
link = 'http://anylink'
ie = Watir::IE.start(link)
# Use click_no_wait
ie.button(:value, 'Display alert box').click_no_wait
dialog = Watir::Dialog.new
# Use the sleep method with any value you need
sleep 0.4
# Click on Popup window button
dialog.button('OK').click
ie.waitForIE
I came across situation where I needed to handle popups on click of radio button as well. Above can also be extended to radiobuttons, checkboxes and other objects as well.
ie.radio(:id,"xyz").click_no_wait
sleep 0.4
dialog = Watir::Dialog.new
dialog.button('OK').click
ie.waitForIE
Good to see your blog.
ReplyDelete