click_no_wait and click! not working <javascript popup>

172 views
Skip to first unread message

Jim Matthews

unread,
Mar 2, 2009, 11:12:14 AM3/2/09
to Watir General
I am trying to deal with javascript popups. I have created the
popupchecker method described on the wiki.

When I used click_no_wait, the popup came up but was not dismissed.
Someone suggested that I try click! instead of click_no_wait because
of some problems mentioned in recent posts. I did that and click!
worked for the first popup. It dismissed it and the script continued.

When the script got to the second popup, neither click_no_wait nor
click! worked to dismiss the popup. I put some "puts" statements is
the popupchecker method and it appears from that, that popupchecker is
not getting called the second time until after I manually dismiss the
second popup.

I know the popupchecker code works because it successfully dismisses
the first popup and because I have used fxri with popupchecker to
dismiss both the popups.

Does anyone have an idea what is going on or something different to
try?

Jim

Jim Matthews

unread,
Mar 3, 2009, 10:52:32 AM3/3/09
to Watir General
Here are the steps to reproduct the problem. First bring up unittests
\html\popups1.html in IE.

\Ruby\lib\ruby\gems\1.8\gems\watir-1.6.2\unittests\html\popups1.html

Next run this script. I have extra "puts" in it to try to figure out
what is going on. They can be remvoed or commented out.

Jim

require 'watir'
require 'watir/ie'
require 'watir/testcase'
require 'watir/contrib/enabled_popup'

class StepTests < Watir::TestCase
def test_01_step_test
browser = Watir::IE.attach(:title, /Test page for/)
browser.row(:index, 3).button(:type, 'button').click!
popupchecker(browser, 'OK')
end
def popupchecker(browser, text)
Timeout::timeout(2) do
begin
puts "Inside begin of popupcuecker."
puts "browser.enabled_popup == #{browser.enabled_popup}"
if browser.enabled_popup
puts "In if in popupchecker."
hwnd = browser.enabled_popup(5)
puts hwnd.to_s
w = WinClicker.new
w.makeWindowActive(hwnd)
w.clickWindowsButton_hwnd(hwnd, text)
end
rescue Timeout::Error
puts 'No popup existed.'
end
end
end
end

Jim Matthews

unread,
Mar 23, 2009, 11:29:57 AM3/23/09
to Watir General

I have figured a few things out with the click_no_wait problem. This
potentially affects any program that uses the Ruby "system" call,
which click_no_wait does. There is also appears to be a problem with
Watir#wait_until, that is used by enabled_popup, which is used to
check for the presence of a popup. The details follow:

First, I think the problem with click_no_wait not actually not
clicking the button/link is a Ruby 1.8.6-27 problem. It is because
the quoted string is not passed into Ruby correctly.

On a Ruby 1.8.6-26 system, the following happens:

C:\>ruby --version
ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]

C:\>ruby -e "puts \"Does this work?\""
Does this work?

C:\>

However, on a 1.8.6-27 system, the following happens:

C:\>ruby --version
ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]

C:\>ruby -e "puts \"Does this work?\""
-e:1: unterminated string meets end of file

C:\>

There is a second problem. When you set the timeout for clicking the
popup button, Watir times out first:
.
.
.
if (ie.enabled_popup)
wc = WinClicker.new
wc.clickWindowsButton(/Internet Explorer/, "OK", 30)
end

>ruby javatest.rb
c:/ruby/lib/ruby/gems/1.8/gems/commonwatir-1.6.2/lib/watir/waiter.rb:
59:in `wait_until': Timed out after 4.006 seconds.
(Watir::Exception::TimeOutException)
from c:/ruby/lib/ruby/gems/1.8/gems/commonwatir-1.6.2/lib/watir/
waiter.rb:80:in `wait_until'
from c:/ruby/lib/ruby/gems/1.8/gems/watir-1.6.2/lib/watir/contrib/
enabled_popup.rb:10:in `enabled_popup'
from javatest.rb:13
>Exit code: 1

So even though I have the click set to not timeout until after 30
seconds, Watir seems to timeout after about 4 seconds.

There is a temporary workaround for this that works for me. Because I
was getting the Watir timeout before the popup came up, I added a
sleep to my popupchecker method before the Timeout::timeout. So the
first part of the popupchecker method looks like this:

def popupchecker(text)
sleep 10
Timeout::timeout(2) do

Note that I give this as a temporary solution until the wait_until is
fixed.

Jim
> > When I usedclick_no_wait,  the popup came up but was not dismissed.

spike

unread,
Apr 14, 2009, 4:25:17 AM4/14/09
to Watir General
sir,

I used the method you suggested but, it is not working i've to click
the popup button manually to go further testing the application. I'm
putting the code i'm using for the handling popup below, please
suggest me corrections that are to be made

require 'Watir'
require 'test/unit'
require 'watir/dialog'
require 'watir/contrib/enabled_popup'

class Manageresources < Test::Unit::TestCase

def test_manage_resources
ie = Watir::IE.start "http://192.168.25.10:215/"
ie.maximize()
ie.text_field(:name, "Login1$UserName").set("")
ie.text_field(:name, "Login1$Password").set("")
ie.checkbox(:name, "Login1$RememberMe").click
ie.button(:value, "Log In").click
ie.link(:href, "http://192.168.25.10:215/administrator/
Default.aspx").click
ie.link(:href, "javascript:__doPostBack
('ctl00$Menu1','Resources')").click
ie.link(:href, "http://192.168.25.10:215/admin/
ManageResources.aspx").click
ie.link(:id, "ctl00_ContentPlaceHolder1_lnkAdd").click
ie.radio(:id, "ctl00_ContentPlaceHolder1_rdCourses_1").click
ie.button(:id, "ctl00_ContentPlaceHolder1_btnNext").click
ie.file_field(:id, "ctl00_ContentPlaceHolder1_Uploadfile").set("D:\
\BCSBI.zip")
ie.button(:id, "ctl00_ContentPlaceHolder1_btnUpload").click

#popup

def popupchecker(text)
sleep 10
Timeout::timeout(2) do
if (ie.enabled_popup)
wc = WinClicker.new
wc.clickWindowsButton(/Windows Internet Explorer/, "OK", 30)
end
end
end

#Below is the code for operations after the popup disappears
if ie.radio(:id,
"ctl00_ContentPlaceHolder1_RdlistisFeedback_1").isSet?
puts "IS FEEDBACK option Yes is selected"
else
ie.radio(:id,
"ctl00_ContentPlaceHolder1_RdlistisFeedback_1").click
end
ie.select_list(:id, "ctl00_ContentPlaceHolder1_DdlAccesstype").set
("Public")
ie.select_list(:id,
"ctl00_ContentPlaceHolder1_DdlApprovaltype").set("Admin")

end
end



On Mar 23, 8:29 pm, Jim Matthews <jim_m...@swbell.net> wrote:
> I have figured a few things out with the click_no_wait problem.  This
> potentially affects any program that uses the Ruby "system" call,
> which click_no_wait does. There is also appears to be a problem with
> Watir#wait_until, that is used by enabled_popup, which is used to
> check for the presence of apopup.  The details follow:
>
> First, I think the problem with click_no_wait not actually not
> clicking the button/link is a Ruby 1.8.6-27 problem.  It is because
> the quoted string is not passed into Ruby correctly.
>
> On a Ruby 1.8.6-26 system, the following happens:
>
> C:\>ruby --version
> ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]
>
> C:\>ruby -e "puts \"Does this work?\""
> Does this work?
>
> C:\>
>
> However, on a 1.8.6-27 system, the following happens:
>
> C:\>ruby --version
> ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]
>
> C:\>ruby -e "puts \"Does this work?\""
> -e:1: unterminated string meets end of file
>
> C:\>
>
> There is a second problem.  When you set the timeout for clicking thepopupbutton, Watir times out first:
> .
> .
> .
> if (ie.enabled_popup)
>   wc = WinClicker.new
>   wc.clickWindowsButton(/Internet Explorer/, "OK", 30)
> end
>
> >ruby javatest.rb
>
> c:/ruby/lib/ruby/gems/1.8/gems/commonwatir-1.6.2/lib/watir/waiter.rb:
> 59:in `wait_until': Timed out after 4.006 seconds.
> (Watir::Exception::TimeOutException)
>     from c:/ruby/lib/ruby/gems/1.8/gems/commonwatir-1.6.2/lib/watir/
> waiter.rb:80:in `wait_until'
>     from c:/ruby/lib/ruby/gems/1.8/gems/watir-1.6.2/lib/watir/contrib/
> enabled_popup.rb:10:in `enabled_popup'
>     from javatest.rb:13
>
> >Exit code: 1
>
> So even though I have the click set to not timeout until after 30
> seconds, Watir seems to timeout after about 4 seconds.
>
> There is a temporary workaround for this that works for me.  Because I
> was getting the Watir timeout before thepopupcame up, I added a
> > > When I usedclick_no_wait,  thepopupcame up but was not dismissed.
> > > Someone suggested that I try click! instead ofclick_no_waitbecause
> > > of some problems mentioned in recent posts.  I did that and click!
> > > worked for the firstpopup.  It dismissed it and the script continued.
>
> > > When the script got to the secondpopup, neitherclick_no_waitnor
> > > click! worked to dismiss thepopup.  I put some "puts" statements is
> > > the popupchecker method and it appears from that, that popupchecker is
> > > not getting called the second time until after I manually dismiss the
> > > secondpopup.
>
> > > I know the popupchecker code works because it successfully dismisses
> > > the firstpopupand because I have used fxri with popupchecker to
> > > dismiss both the popups.
>
> > > Does anyone have an idea what is going on or something different to
> > > try?
>
> > > Jim- Hide quoted text -
>
> - Show quoted text -

spike

unread,
Apr 16, 2009, 12:32:39 AM4/16/09
to Watir General
Hi sir,

thanks a lot for the solution it worked for me, since a week i had
problem with handling popup. thankyou very much.

spike

unread,
Apr 16, 2009, 1:36:04 AM4/16/09
to Watir General
This solution worked fine for popup raised when a button is clicked,
but it is not working for popup raised when clicked on a link, please
suggest some solution

On Mar 3, 8:52 pm, Jim Matthews <jim_m...@swbell.net> wrote:

ash

unread,
May 1, 2009, 11:08:33 AM5/1/09
to Watir General
I am also receiving the TimeOutException but am using solution #4 from
http://wiki.openqa.org/display/WTR/JavaScript+Pop+Ups so do not have
anywhere to place the sleep.

Segment of my script;
ie.button(:class, "button_checkout").click_no_wait
hwnd = ie.enabled_popup(5)
if (hwnd) #yeah! a popup
popup = WinClicker.new
popup.makeWindowActive(hwnd)
popup.clickWindowsButton("Windows Internet Explorer", "OK", "30")
end

Where should I put the 'sleep'?
Obviously I may be missing the point so feel free to shout at me if
necessary.

Cheers...Ash
Reply all
Reply to author
Forward
0 new messages