if dialog.button(:name,“OK”).exists? ?How can I validate OK exist on
dialog?
dialog.button(‘OK’).click #click OK button
else
dialog.close #close if button doesn’t exist
end
end
I got it to work, so now anyone can use it. If you know how do do it
better, please add to this thread.
#################################################################################Written
by: Darin D. #Date: Feb 12, 2008 #Purpose: Handles Popups
################################################################################
require ‘watir’
require ‘watir\contrib\enabled_popup’
require ‘watir/dialog’
require ‘watir/winClicker’
def startClicker(button)
sleep 2
Timeout::timeout(1) do
begin
hwnd1 = $ie.enabled_popup(9)
w = WinClicker.new #Get Popup Text
popup_text = w.getStaticText_hWnd(hwnd1) #Verify popup_text match expected text
if popup_text.to_s == “Please select an interaction type”
# Click buttton
w.clickWindowsButton_hwnd(hwnd1, “#{button}” ) #Needed sleep time
sleep 0.1 #Check to see if popup still exists
Timeout::timeout(1) do
begin
hwnd = $ie.enabled_popup(9)
puts “The popup existed but the expected button didn’t
exist, so popup was closed without clicking a button”
dialog = Watir::Dialog.new
dialog.close
rescue Timeout::Error
puts “The popup existed and the expected button was clicked”
end
end
else #Populates Error Results & Close Dialog
puts “Popup existed, but the current text didn’t match the
expected text, so popup was closed without clicking a button”
dialog = Watir::Dialog.new
dialog.close
end
rescue Timeout::Error
puts “No Popup existed”
end
end
end