Ok, I have gone through your codes and actually wrote the script similar to
yours.
I don't understand when you said 'click_no_wait' is not working.
To me, it is working just fine.
Here is my codes and dismiss the js popup.
require 'watir/ie'
require 'watir/contrib/enabled_popup'
def handle_nextpopup(sButton=nil)
while true
begin
hwnd = $ie.enabled_popup(5)
rescue
hwnd = nil
end
if (hwnd) #yeah! a popup
popup = WinClicker.new
popup.makeWindowActive(hwnd)
if sButton != nil
begin popup.clickWindowsButton_hwnd(hwnd, sButton ); rescue; end
else
autoit = WIN32OLE.new("AutoItX3.Control")
autoit.Send('{ESC}')
sleep(2)
end
break
end
sleep(2)
end
end
link = 'http://www.w3schools.com/js/tryit_view.asp?filename=tryjs_alert'
$ie = Watir::IE.start(link)
# ensure popup won't block Watir
$ie.button(:value, 'Display alert box').click_no_wait
#wait for popup
handle_nextpopup("OK")
Please be more specific on what you found as problem.
Michael
----- Original Message ----
From: "[email protected]" <[email protected]>
To: Watir General <[email protected]>
Sent: Thursday, December 11, 2008 6:47:52 AM
Subject: [wtr-general] Re: button.Click_No_Wait only highlights the button,
does not click
Okay, so: autoit. Here's some code that I got off another site that
doesn't work to dismiss popups:
require 'watir'
require 'watir/dialog'
def check_for_popups
autoit = WIN32OLE.new('AutoItX3.Control')
#
# Do forever - assumes popups could occur anywhere/anytime in your
application.
loop do
# Look for window with given title. Give up after 1 second.
ret = autoit.WinWait('Windows Internet Explorer', '', 1)
#
# If window found, send appropriate keystroke (e.g. {enter},
{Y}, {N}).
if (ret==1) then autoit.Send('{enter}') end
#
# Take a rest to avoid chewing up cycles and give another
thread a go.
# Then resume the loop.
sleep(3)
end
end
#
# MAIN APPLICATION CODE
# Setup popup handler
$popup = Thread.new { check_for_popups } # start popup handler
at_exit { Thread.kill($popup) } # kill thread on exit of
main application
link = 'http://www.w3schools.com/js/tryit_view.asp?
filename=tryjs_alert'
ie = Watir::IE.start(link)
# ensure popup won't block Watir
ie.button(:value, 'Display alert box').click!
dialog = Watir::Dialog.new
# Need to be able to poll window to exist
sleep 7.0
# Remember that the only button to click is OK!
dialog.button('OK').click
# Wait for dialog to do its stuff
# and wait for IE to return to live
ie.waitForIE
I got the popup-handling code from
http://wiki.openqa.org/display/WTR/JavaScript+Pop+Ups,
and the rest of it is from http://en.wikipedia.org/wiki/Watir#Handling_pop-ups.
Is the above code put together correctly?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Watir General" group.
To post to this group, send email to [email protected]
Before posting, please read the following guidelines:
http://wiki.openqa.org/display/WTR/Support
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/watir-general
-~----------~----~----~----~------~----~------~--~---