<html>
<head>
<style>
P
{
margin:0px;
padding:0px
}
body
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body>
Hi Shalini,<BR>
&nbsp;<BR>
Here is the method to click the OK button on a java alert<BR>
&nbsp;<BR>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<FONT face="courier new">#Put this method in your script:</FONT><BR>
<FONT face="courier new">def startClicker( button , waitTime = 3)<BR>&nbsp;&nbsp; w = WinClicker.new<BR>&nbsp;&nbsp; longName = $ie.dir.gsub("/" , "\\" )<BR>&nbsp;&nbsp; shortName = w.getShortFileName(longName)<BR>&nbsp;&nbsp; c = "start ruby #{shortName}\\watir\\clickJSDialog.rb #{button} </FONT><FONT face="courier new">#{waitTime} "<BR>&nbsp;&nbsp; puts "Starting #{c}"<BR>&nbsp;&nbsp; w.winsystem(c)<BR>&nbsp;&nbsp; w=nil<BR>&nbsp;end</FONT><BR>
<FONT face="Courier New"></FONT>&nbsp;<BR>
<FONT face="Courier New">#Then call it right&nbsp;<FONT color=#000000>before</FONT><STRONG><FONT color=#ff0000> </FONT></STRONG>you click the button (or whatever) that<BR>causes the javascript popup to display:</FONT><BR>
<FONT face="courier new">startClicker("OK" , 3)<BR>$ie.button("Submit").click</FONT><BR>
<FONT face="Courier New"></FONT>&nbsp;<BR>
<FONT face="Courier New">Thanks &amp; Regards,</FONT><BR>
<FONT face="Courier New">Anupama</FONT><BR></BLOCKQUOTE>
<BR><BR>&gt; Date: Thu, 5 Apr 2007 00:59:09 -0500<BR>&gt; From: forum-watir-users@openqa.org<BR>&gt; To: wtr-general@rubyforge.org<BR>&gt; Subject: Re: [Wtr-general] How do I click the "OK" button on a java alert?<BR>&gt; <BR>&gt; Hi all,<BR>&gt; <BR>&gt; I am new to ruby, and have searched these forums for answers, but have not found anything that seems to work or help me. (including links to FAQ's which do not appear to be available anymore)<BR>&gt; <BR>&gt; Situation:<BR>&gt; I am writing ruby/watir scripts to automate tests against a website/application. On one page there are a date field and a "Search" button.after entering wrong dae in date field a popup alert opens and display message please enter valid date this dialog box also has a "OK" button.<BR>&gt; <BR>&gt; Problem:<BR>&gt; I am unable to gain access to the java alert dialog to gain control of the button and click it. The modal dialog have a :title,"Microsofte Internet Explorer".but error comes unable to locate with window with title "Microsoft Internet Explorer" . So my tests "hang" while it waits for the button to be clicked before it can continue on.<BR>&gt; <BR>&gt; I also do not have access to the webcode (java code) to change it, but I know that the dialog is simply invoked with 'alert("&lt;text&gt;")'.<BR>&gt; <BR>&gt; Things I have tried (with no success...)<BR>&gt; $ie = IE.attach(:title, "Microsoft Internet Explorer")<BR>&gt; $ie.button(:id, '2').click<BR>&gt; <BR>&gt; #<BR>&gt; #require 'win32ole' # already included if you use 'require watir'<BR>&gt; #<BR>&gt; # Function to look for popups<BR>&gt; #def check_for_popups<BR>&gt; # autoit = WIN32OLE.new('&lt;nowiki&gt;AutoItX3&lt;/nowiki&gt;.Control')<BR>&gt; #<BR>&gt; # Do forever - assumes popups could occur anywhere/anytime in your application.<BR>&gt; #loop do<BR>&gt; # Look for window with given title. Give up after 1 second.<BR>&gt; # ret = autoit.&lt;nowiki&gt;WinWait&lt;/nowiki&gt;('Popup Window Title', '', 1)<BR>&gt; #<BR>&gt; # If window found, send appropriate keystroke (e.g. {enter}, {Y}, {N}).<BR>&gt; #if (ret==1) then autoit.Send('{enter}') end<BR>&gt; #<BR>&gt; # Take a rest to avoid chewing up cycles and give another thread a go.<BR>&gt; # Then resume the loop.<BR>&gt; #sleep(3)<BR>&gt; #end<BR>&gt; # end<BR>&gt; #<BR>&gt; # MAIN APPLICATION CODE<BR>&gt; # Setup popup handler<BR>&gt; # $popup = Thread.new { check_for_popups } # start popup handler<BR>&gt; #at_exit { Thread.kill($popup) } <BR>&gt; <BR>&gt; ##$ie.button(:id, "ctl00_MainContentPlaceHolder_btn_Search").fire_event("onclick")<BR>&gt; ## w = WinClicker.new()<BR>&gt; <BR>&gt; #("#32770", "Microsoft Internet Explorer", <BR>&gt; <BR>&gt; ##handle = w.getWindowHandle("Microsoft Internet Explorer")<BR>&gt; ##puts handle<BR>&gt; <BR>&gt; ##w.makeWindowActive(handle)<BR>&gt; #w.button(:value,"OK").click<BR>&gt; ##w.clickWindowsButton_hwnd(handle,"OK")<BR>&gt; ##w.close <BR>&gt; #ie2=IE.attach(:id,"00000fdc")<BR>&gt; #$ie2.enter<BR>&gt; #ie2.button(:name, add.wacTagAdd).getOLEObject.click<BR>&gt; #w = WinClicker.new()<BR>&gt; <BR>&gt; #w.clickWindowsButton("Microsoft Internet Explorer", "OK" , maxWaitTime=2 )<BR>&gt; #w = nil<BR>&gt; #ie2.close <BR>&gt; #puts "ent 1"<BR>&gt; #$autoit = WIN32OLE.new('AutoItX3.Control') <BR>&gt; #puts "ent 2"<BR>&gt; # $autoit.WinWait("Microsoft Internet Explorer", "", 0)<BR>&gt; #puts "ent 3"<BR>&gt; #$autoit.WinActivate("Microsoft Internet Explorer")<BR>&gt; #puts "ent 4"<BR>&gt; #$autoit.send_keys('enter')<BR>&gt; #$autoit.Winbutton(:name,"OK").click<BR>&gt; #$autoit.ControlClick("Microsoft Internet Explorer", "", "OK")<BR>&gt; #clickWindowsButton("Microsoft Internet Explorer" , "&amp;OK" )<BR>&gt; #$autoit.Send("enter")<BR>&gt; #puts "ent 5"<BR>&gt; #$autoit.WinWait("Microsoft Internet Explorer", "Look &amp;in", 3) <BR>&gt; <BR>&gt; #$autoit.ControlSetText("Microsoft Internet Explorer", "", "", "#{$path}") <BR>&gt; <BR>&gt; #$autoit.ControlClick("Microsoft Internet Explorer", "", "&amp;OK")<BR>&gt; #$ie.link(:text, 'New Window').click_no_wait<BR>&gt; #IE.attach_timeout = 1.0<BR>&gt; #ie_new = IE.attach(:title, "Microsoft Internet Explorer")<BR>&gt; #assert(ie_new.text.include?("OK"))<BR>&gt; #ie_new.button(:title,"OK").click<BR>&gt; #begin<BR>&gt; <BR>&gt; #autoit = WIN32OLE.new('AutoItX3.Control') <BR>&gt; <BR>&gt; #autoit.ControlClick("Microsoft Internet Explorer",'', '&amp;OK')<BR>&gt; <BR>&gt; #autoit.ControlClick("Security Information",'', '&amp;OK')<BR>&gt; <BR>&gt; #autoit.ControlClick("Security Alert",'', '&amp;OK')<BR>&gt; <BR>&gt; #sleep(1)<BR>&gt; <BR>&gt; #rescue Exception =&gt; e<BR>&gt; <BR>&gt; #puts "error"<BR>&gt; <BR>&gt; #end<BR>&gt; #hwnd = $ie.enabled_popup(5) <BR>&gt; #puts "hwnd"<BR>&gt; #if(hwnd) <BR>&gt; <BR>&gt; #w = WinClicker.new<BR>&gt; <BR>&gt; # w.makeWindowActive(hwnd)<BR>&gt; #w.clickJSDialog_NewProcess(button = "OK" )<BR>&gt; <BR>&gt; <BR>&gt; # puts hwnd.to_s<BR>&gt; #$ie.Window("Microsoft Internet Explorer").button(:title, "OK").click<BR>&gt; #pp=TC_PopUps.new<BR>&gt; #pp.startClicker( "OK" , waitTime = 0.5)<BR>&gt; Versions:<BR>&gt; ruby 1.8.4<BR>&gt; watir 1.5.1.1127<BR>&gt; ie 6<BR>&gt; _______________________________________________<BR>&gt; Wtr-general mailing list<BR>&gt; Wtr-general@rubyforge.org<BR>&gt; http://rubyforge.org/mailman/listinfo/wtr-general<BR><BR><br /><hr />Take a break and play crossword puzzles - FREE! <a href='http://games.msn.com/en/flexicon/default.htm?icid=flexicon_ wlmemailtaglinemarch07' target='_new'>Play Now!</a></body>
</html>