Clicking a JavaScript Dialog using Watir

There will soon be an easy way to click and generally deal with JavaScript Dialogs with Watir (Web Application Testing in Ruby, pronounced "WATER"). It's always been possible, but the team is working on ways to make it easier. Until that day comes, we use the old way. Mark Cain posted sample code recently on the Wtr-General Mailing List. I'd been meaning to post my code that fires up another Ruby "thread," but his is arguably simpler if not slightly brute force. Thanks Mark!

#Put this method in your script:

def startClicker( button , waitTime = 3)
   w = WinClicker.new
   longName = $ie.dir.gsub("/" , "\\" )
   shortName = w.getShortFileName(longName)
   c = "start ruby #{shortName}\\watir\\clickJSDialog.rb #{button}
#{waitTime} "
   puts "Starting #{c}"
   w.winsystem(c)
   w=nil
 end

#Then call it right before you click the button (or whatever) that
causes the javascript popup to display:

startClicker("OK" , 3)
$ie.button("Submit").click

Tracked by:
"Scott rocks" (Keyvan Nayyeri) [Trackback]
Saturday, January 14, 2006 1:48:09 AM UTC
I thought I read somewhere that they had deprecated WinClicker. I thought the preferred method was something along the lines of:

Thread.new { sleep 0.1; WindowHelper.new.push_security_alert_yes }

I kinda prefer the way Selenium handles it. It just has a simple "verifyAlert" command. I'm not real sure on the details of how it works (never really looked), but I think it actually supresses the execution of alert().
Thursday, January 19, 2006 7:41:36 PM UTC
Is there any way of handling a Javascript Popup Window with a select drop-down listing?
Thanks in advance.
Comments are closed.
Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer’s view in any way.