On 10/5/06, Cain, Mark <[EMAIL PROTECTED]> wrote:

The _javascript_ Alert, Confirm, Prompt, Security, File Save, File Download, File Upload, error message, and login (I think this is a complete list but there may be others) are all a special type of modal popup dialog window—there isn't a different one.   In order to handle these types of popups you have to start another thread independent of your $ie thread OR you have to not block the process by using click_no_wait.

There are two ways (that actually both use the WInClicker).  The first one is listed below that works with the older versions of Watir.  The second (I have found after using them both) is more reliable than the first but require you having a Watir version greater than 1079 because of some fixes to click_no_wait (can't remember the exact version).  You can get them here:  http://wiki.openqa.org/display/WTR/Development+Builds

 

First method (works with Watir 1.4.x):

def jsAlert(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, before the button you want to click that generates the popup, add in:

jsAlert("OK", 3)

ie.button(:name, "woohoo").click     # This is the button you want to click that generates the popup

 

Second Method (faster and more reliable):

require 'watir\contrib\enabled_popup'

 

<Your code>

 

$ie.button("Button Label Text").click_no_wait

 

# use click_no_wait to click the button that invokes the JS Alert $ie.button.click_no_wait

 

hwnd = ie.enabled_popup (5)               # get a handle if one exists

if (hwnd)                             # yes there is a popup

  w = WinClicker.new

     w.makeWindowActive(hwnd)

# "OK" or whatever the name on the button is

  w.clickWindowsButton_hwnd(hwnd, "OK")   

end

 

NOTE:  If you are using IE7 then the title on the JS Alert box is different then IE6+ so you will need to alter you WinClicker.rb file for either method.

\ruby\lib\ruby\site_ruby\1.8\watir\WinClicker.rb Lines 113 and 144.

IE6 = "Microsoft Internet Explorer"

IE7 = "Windows Internet Explorer"

 

Hope this helps,

 

--Mark


_______________________________________________
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general


Hello,
I have been trying to use the second method described above with no success. I am trying to clear a security dialog that appears after clicking a "Sign In" button. I can see that the button gets clicked, then the script blocks. If I kill the script ( by closing the browser, or whatever ) I get this error message:

c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.1.1100/./watir/contrib/enabled_popup.rb:10:in `enabled_popup': uninitialized constant Watir::PageContainer::GetWindow (NameError)
from c:/ruby/lib/ruby/gems/1.8/gems/watir- 1.5.1.1100/./watir/contrib/enabled_popup.rb:9:in `until_with_timeout'
from c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.1.1100/./watir.rb:210:in `wait_until'
from c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.1.1100/./watir.rb:210:in `until_with_timeout'
from c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.1.1100/./watir/contrib/enabled_popup.rb:9:in `enabled_popup'
from C:/ruby/mattj/scanmus/scanmus3.rb:79

Can anyone tell me what the problem is, or how I can debug this further? Why is this not initialized? Does that mean I have some kind of path or other environment problem. I am using WinXP SP2, ruby 1.8.2 (2004-12-25) [i386-mswin32], watir 1.5.1.1100.

Thanks in advance.

--
MattJ
[EMAIL PROTECTED]
_______________________________________________
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to