Q. How do I deal with javascript popup’s?
A. Invoke the autoit function library with the .click_no_wait method…
You will need to install autoit. You can download it here, once installed you can call the function library using the win32OLE extension library.
Example html:
<html> <head> <script language="javascript"> function msgbox (textstring) { alert (textstring) } </script> </head> <body id="test_00test_0107" onload=""> <form> <input name="text1" type=text> <input name="submit" type=button value="show me" onclick="msgbox(form.text1.value)"> </form> </body> </html>
Example watir:
require 'watir' require 'rubygems' require 'win32ole' autoit = WIN32OLE.new('AutoItX3.Control') @b.goto('http://justaddwatir.com/watir/test_html/tc_0101_0200/test_0107.html') @b.text_field(:name,"text1").set("Justaddwatir") @b.button(:name,"submit").click_no_wait autoit.WinWaitActive("[Class:#32770]") result =autoit.ControlClick("[Class:#32770]","","Button1") puts "successful click =1 unsuccessful =0, the result was "+ result
In order for the autoit function to execute, you need to use the .click_no_wait method in watir before the autoit function. This is because once the pop up is presented, the focus comes off the IE window and the script will pause. The .click_no_wait tells the script to continue running regardless of what happens next.
You may use the autoit window identifier to get the properties of the pop up and the button attributes.
2 Comments »
RSS feed for comments on this post. TrackBack URL
How can you handle pop-ups that arent javascript dialogues or alerts? Just a vanilla pop-up, like adding a target attribute to a link?
[...] - bookmarked by 2 members originally found by kimmi1234 on 2008-11-11 Q. How do I deal with javascript popup’s? http://justaddwatir.com/watir/q-how-do-i-deal-with-javascript-popups/ - bookmarked by 6 members [...]