[Wtr-development] A solution for JavaScript dialogs in Watir

Alister Scott alister.scott at gmail.com
Thu Oct 28 22:16:21 EDT 2010


One of the guys I am working with setting up Cucumber and Watir on a
ThoughtWorks project told me about a way to get rid of the pesky JavaScript
dialogs that cause Watir scripts to be unstable. It involves overriding the
JavaScript function to always return true, so the dialogs never appear.

I wrote an example for Watir:

require 'rubygems'
require 'watir'
b = Watir::Browser.start "http://www.sislands.com/coin70/week1/dialogbox.htm
b.execute_script "window.confirm = function() { return true; }"
b.execute_script "window.alert = function() { return true; }"
b.execute_script "window.prompt = function() { return true; }"
b.button(:value => 'confirm').click

What do you think of this? Is it worthwhile putting this out for Watir users
to see and use?


Alister Scott
Brisbane, Australia
Watir Web Master: http://watir.com
Blog: http://watirmelon.com
LinkedIn: http://www.linkedin.com/in/alisterscott

"There are two ways to get enough: One is to continue to accumulate more and
more. The other is to desire less." *~ G. K. Chesterton*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/wtr-development/attachments/20101029/fc75a39d/attachment.html>

More information about the Wtr-development mailing list