Scott Hanselman

Clicking a JavaScript Dialog using Watir

January 14, 2006 Comment on this post [2] Posted in Ruby | Watir | Javascript
Sponsored By

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

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
January 14, 2006 5:48
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().
Cam
January 19, 2006 23:41
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.