How do I get the popup text using watir

D

Darin Duphorn

I need to get the text to verify the correct popup appeared
I also need to verify the button I want to click exist on the popup

Below is the code.

#Click Button
$ie.button($attribute_nm.to_sym,$attribute_val).click_no_wait
dialog = Watir::Dialog.new
puts dialog
# Need to be able to poll window to exist
sleep 0.4

if dialog.exists?
?how can I get the dialog text?

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

Thanks,
DD
 
D

Darin Duphorn

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 Duphorn
#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

# MAIN APPLICATION CODE
$ie = Watir::IE.new
$ie.goto("https://www-test.redbrickhealth.com/advisor/web/portal/login")

$ie.text_field("name","_58_login").set("jadvisor")
$ie.text_field("name","_58_password").set("test")
$ie.button("type","submit").click

$ie.radio:)id,"startInteraction_theInteractionType_id1").set

$ie.button:)type, "submit").click_no_wait

#Validate Button & Click button
startClicker("OK")

$ie.waitForIE
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top