# How do I get the popup text using watir

**URL:** <https://www.ruby-forum.com/t/how-do-i-get-the-popup-text-using-watir/128580>\
**Category:** Ruby\
**Created:** [February 9, 2008, 12:07am UTC](https://www.ruby-forum.com/t/how-do-i-get-the-popup-text-using-watir/128580 "2008-02-09T00:07:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ddad01](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/919ad9/32.png) [@ddad01](https://www.ruby-forum.com/u/ddad01)\
**Post date:** [February 9, 2008, 12:07am UTC](https://www.ruby-forum.com/t/how-do-i-get-the-popup-text-using-watir/128580/1 "2008-02-09T00:07:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ddad01](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/919ad9/32.png) [@ddad01](https://www.ruby-forum.com/u/ddad01)\
**Post date:** [February 12, 2008, 3:55pm UTC](https://www.ruby-forum.com/t/how-do-i-get-the-popup-text-using-watir/128580/2 "2008-02-12T15:55:54Z")

</div>

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

# MAIN APPLICATION CODE

$ie = Watir::IE.new  
$ie.goto(“[https://www-test.redbrickhealth.com/advisor/web/portal/login](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
