Home > watir > watir: handle javascript confirm popups

watir: handle javascript confirm popups

Watir 1.6.2
IE 6

recently I had a rough time getting javascript confirmation popup's interaction to work, although, I know it must, as there is a unit test for it. (C:\ruby\lib\ruby\gems\1.8\gems\watir-1.6.2\unittests\popups_test.rb)

There is also a page of potential solutions, although, the few I tried did not work for me (watir javascript pop up page)

which I couldn't run, because the shipped unit tests don't work 'the easy way' in 1.6, see Run+the+Watir+Unit+Tests

I would have had to get the tree from github and build it, details:
Building+Watir
which, I didn't really have the time to do this morning.)

I had to modify the code from the unit test to get it to work in my test. (I run Win XP in Parrallels from Mac OSX, it's possible that has something to do with it not working as advertised)

Anyway, short story, I used '"start ruby" instead of "start rubyw"'
ruby.exe and rubyw.exe are ruby interpreters for windows
the difference is rubyw.exe doesn't launch a DOS shell to run.
(ref: Running Ruby Under Windows)
Yes, it's uglier and less convenient to have the dos window pop up but at this time, I'm just psyched to have my tests passing

Example:

html:
-------
<html>
<head>
<script type="text/javascript" language="javascript"> 

document.write('Hello World!');
function process(args){
   document.write("You said " + args)
}

</script>
</head>

<body>
<form>
<input type="button" value="Delete"
    on Click="return confirm('Really, Delete?') && process('OK')"
</form>

</body>
</html>

ruby/watir code:
------------------
  startClicker("OK")
  @ie.button(:value, 'Delete').click
  @ie.contains_text('Successfully  removed!')

  def startClicker( button , waitTime = 0.5)
    w = WinClicker.new
    jsd = 'c:\\ruby\\lib\\ruby\\gems\\1.8\\gems\\WATIR-~1.2\\lib\\watir\\clickJSDialog.rb'
    c = "start ruby #{jsd } #{button } #{ waitTime} "
    puts "Starting #{c}"
    w.winsystem(c )
    w = nil
  end
Categories: watir Tags:
  1. No comments yet.