Clicking OK on Pop Up with Watir

251 views
Skip to first unread message

ranjith kumar

unread,
May 17, 2011, 12:24:52 PM5/17/11
to watir-...@googlegroups.com
Hello Team,
 
In my application i have pop up where i have to select "Ok" or "Cancel".
 
I tried http://wiki.openqa.org/display/WTR/Pop+Ups" given in this case.
 
But i am unable to do so exactly..
 
 
Please help me in solving this issue.
 
Thanks in Advance.
 
Regards,
Ranjith

Ashok Tulachan

unread,
May 17, 2011, 1:12:49 PM5/17/11
to watir-...@googlegroups.com
Hi Ranjith,
 
This might help.
  
$b.button(:id, "find id of the button").click

ranjith kumar

unread,
May 17, 2011, 11:29:31 PM5/17/11
to watir-...@googlegroups.com
Hi,
 
Thanks for the prompt reply.
The pop up which i am getting , i am unable to trace the button id.I am attching the snap shot of that pop up.
 
Please suggest a way forward.
 
Thanks

pOPUP.doc

Steven Coleman

unread,
May 18, 2011, 1:21:09 PM5/18/11
to watir-...@googlegroups.com
Ranjith,

Do you have to actually click the OK button on this confirm popup or would it be acceptable to overide the popup?

We've had this problem on our team and we were able to click the button locally, but were struggling with getting this click to happen under a Hudson service on our application. So after checking http://wiki.openqa.org/display/WTR/JavaScript+Pop+Ups, we went with the simplest solution of just overriding the confirm popups by sending a "true" value as they occur. This wouldn't help if you are testing the popup, but it would get the automation to move past.

Below is are some examples of the code that sends a true value to the javascript confirm popup. @tab_browser is an instance of Watir::IE.browser. The first example is sending the true for a popup on the main browser, while the other example is sending the true for a popup on a frame within the browser.

@tab_browser.document.parentWindow.execScript("window.confirm = function() {return true}")

@tab_browser.frame(:id, frame_id).document.parentWindow.execScript("window.confirm = function() {return true}")

Hope this helps you,

Steve

Steven Coleman

unread,
May 18, 2011, 1:24:52 PM5/18/11
to watir-...@googlegroups.com
I forgot to post that those code examples need to be called prior to the click that launches the pop up. Also, you'll need to click using click_no_wait.

Thanks,

Steve

Chuck van der Linden

unread,
May 18, 2011, 4:49:11 PM5/18/11
to Watir General
>But i am unable to do so exactly..

That page provides information and multiple approaches for dealing
with 12 different types of popups. Telling us "I am unhable to do so
exactly" is about as usless as it gets in terms of trying to provide
US with the information we need to help YOU.

Lets start with this,
1) have you at least managed to identify which type of popup you are
facing?
2) What have you tried (code please) to deal with the popup and what
EXACTLY was the result?
3) provide page code if you can, either the code that creates the
popup on the client side, or page source for the portion of the page
where the popup is coded.

nobody here can see your screen, we can't read your mind, we can't
just do your job for you when you say something equivalent to 'it's
broke please help' we need more than that in order to help you. On
the internet and in forums like this, the help you get is directly
proportional to the information you give to help identify and
troubleshoot your problem. If you can't give us something to work
with, expect nothing in return.

On May 17, 9:24 am, ranjith kumar <ranjith....@gmail.com> wrote:
> Hello Team,
>
> In my application i have pop up where i have to select "Ok" or "Cancel".
>
> I triedhttp://wiki.openqa.org/display/WTR/Pop+Ups" given in this case.

ranjith kumar

unread,
May 20, 2011, 12:02:58 AM5/20/11
to watir-...@googlegroups.com
Hello Team,
 
I have gone through one of the watir forums i found the code with auto it to click the pop ups.
The code is working well with firefox browser but not with IE.
Is there anything need to be changed in the below code to work with IE for pop up.
 
 
require 'win32ole'  # already included if you use 'require watir'
#
# Function to look for popups
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('Microsoft Internet Explorer', '', 1)
        #
        # If window found, send appropriate keystroke ({OK},{Cancel}).
        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
$popup = Thread.new { check_for_popups }  # start popup handler
at_exit { Thread.kill($popup) }

 

Please suggest.

Super Kevy

unread,
May 20, 2011, 10:05:58 AM5/20/11
to Watir General
What it the click you are using that opens the popup is it
click or click_no_wait?


On May 19, 11:02 pm, ranjith kumar <ranjith....@gmail.com> wrote:
> Hello Team,
>
> I have gone through one of the watir forums i found the code with auto it to
> click the pop ups.
> The code is working well with firefox browser but not with IE.
> Is there anything need to be changed in the below code to work with IE for
> pop up.
>
> *require 'win32ole'  # already included if you use 'require watir'
> #
> # Function to look for popups*
> *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('Microsoft Internet Explorer', '', 1)
>         #
>         # If window found, send appropriate keystroke ({OK},{Cancel}).
>         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
> $popup = Thread.new { check_for_popups }  # start popup handler
> at_exit { Thread.kill($popup) }
> *
>
> **
> *Please suggest.
>
> *
> > Before posting, please readhttp://watir.com/support. In short: search
> > watir-genera...@googlegroups.com- Hide quoted text -
>
> - Show quoted text -

Shri

unread,
May 20, 2011, 5:02:40 PM5/20/11
to Watir General
Try below code,
ai_instance=WIN32OLE.new('AutoItX3.Control')
if ai_instance.WinWait("Microsoft Internet Explorer", "", 15) == 1
then # If ai_instance is found
puts "Found Pop-up"
ai_instance.ControlFocus("Microsoft Internet
Explorer",popup_msg_actual,"OK") # Set the focus on OK button
puts "Focus is set"
ai_instance.ControlClick("Microsoft Internet
Explorer",popup_msg_actual,"OK","") # Click the OK button
end

Please make sure that the pop up trigger link should be clicked using
click_no_wait(for ruby 1.8.6) or click! (for ruby 1.8.7) or try around
with both methods.

The Above code is working for me, let me know your results.

Cheers,
Shri
> > > watir-general+unsubscr...@googlegroups.com- Hide quoted text -
Reply all
Reply to author
Forward
0 new messages