Time and again I have faced issues where the WATIR attach method, that
returns a handle to a popup window, has misbehaved.

Specifically I have noticed this on somewhat slow connections. In Cases
where the pop up windows take some time to get rendered on the client
machine, the attach method throws an exception saying that it coud not find
the window.

I have been using WATIR 1.4.x extensively for my projects.

I came up with this small solution that would grab the window no matter how
slow the connection is. Can someone think of a better way to do it, or does
this solution look viable?

def GTools.waitForPopUp(ie, title)
   iePopUp = ''
   popupGrabber = false
   popupGrabberCounter = 0
     #I'll wait for the popup to come up... I'll make some iterations and
then I'll stop iterating
     #Ideally the number of iterations to be made should be made
configurable (number 21)
   while(popupGrabber == false && popupGrabberCounter <= 21)
     begin
       rxp = Regexp.new(title)
       iePopUp = Watir::IE.attach(:title, rxp)
           # I will reach this point only if attach does not throw an
exception
       popupGrabber = true
     rescue Exception => ex
         # If the code reaches this block it means that the pop up window
that
         # u were trying to grab using attach was not served up by the
WebServer
         # set the Grabber flag to false and return back into the loop
       print "Rescued Exception\n"
       popupGrabber = false
     end
     popupGrabberCounter = popupGrabberCounter + 1
     if(popupGrabberCounter >= 21)
           raise GUIException("PopUp Timeout.... No PopUp Window having
title " + title + " was found")
     end
     return iePopUp
   end

When I use this workaround method I have noticed that the code enters the
rescue block quite anumber of times before it attaches successfully to the
window.

I am eager to know if there is a better way to do this?

--
Dhruv
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to