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
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.
About Newsletter
Thanks in advance.
Comments are closed.
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().