Handling Java script Popup with Ruby in WATIR

2,109 views
Skip to first unread message

AQUA

unread,
Apr 27, 2012, 2:42:46 AM4/27/12
to watir-...@googlegroups.com
Hi All,

I have been working on WATIR for sometimes, but finding issues in handling Java Script pop-ups.

on the screen i m testing there is a on_click event. I tried AutoIt and some other examples avaliable on WATIR wiki at http://wiki.openqa.org/display/WTR/JavaScript+Pop+Ups

Most of the examples work with click_no_wait statment. But when I use fire_event('onclick') the popup is generated the the execution halts till I manually click the pop-up button. This doesn't happens with click_no_wait.

Can any one assist me on how can I work out a solution with fire_event as I also need to fire events like onblur, onhover, etc.


Thanks and & Regards,
Manav Gupta
Bangalore.

Željko Filipin

unread,
Apr 27, 2012, 4:07:34 AM4/27/12
to watir-...@googlegroups.com
On Fri, Apr 27, 2012 at 8:42 AM, AQUA <manavk...@gmail.com> wrote:
> I have been working on WATIR for sometimes, but finding issues in handling Java Script pop-ups.

If you are using watir-webdriver, this could help:

AQUA

unread,
Apr 30, 2012, 1:19:33 AM4/30/12
to watir-...@googlegroups.com
No I have been using, WATIR. And the issue I m facing is; basically I have been able to handle the popup using some of the examples available on WATIR wiki. But only with click_no_wait. Whenever I use fire_event the the javascript is executed but the execution flow stuck until I manually click the ok button. Hence the flow never enters the section of the code that is used for handling pop-up without manual interference.

Thanks & Regards,
Manav

Chuck van der Linden

unread,
Apr 30, 2012, 1:13:06 PM4/30/12
to watir-...@googlegroups.com
consider moving to watir-webdriver perhaps?

Bhavesh

unread,
May 1, 2012, 4:28:08 PM5/1/12
to Watir General
If you have autoit installed, then you can create a small script which
look for the window title and the button.

As soon as that titles window is there, it will clck the button.

Sample may be like :

############

require 'win32ole'

begin
autoit = WIN32OLE.new('AutoItX3.Control')

loop do
sleep(30)
autoit.ControlClick("Microsoft Office Outlook",'', 'OK')
autoit.ControlClick("Security Information",'', '&Yes')
autoit.ControlClick("Security Alert",'', '&Yes')
sleep(20)

end
Send("{SPACE}")

rescue Exception => e
puts e
end

############

Have this script runing when you run your script.

Bhavesh

On Apr 30, 10:13 am, Chuck van der Linden <sqa...@gmail.com> wrote:
> consider moving to watir-webdriver perhaps?
>
>
>
>
>
>
>
> On Sunday, April 29, 2012 10:19:33 PM UTC-7, AQUA wrote:
>
> > No I have been using, WATIR. And the issue I m facing is; basically I have
> > been able to handle the popup using some of the examples available on WATIR
> > wiki. But only with click_no_wait. Whenever I use fire_event the the
> > javascript is executed but the execution flow stuck until I manually click
> > the ok button. Hence the flow never enters the section of the code that is
> > used for handling pop-up without manual interference.
>
> > Thanks & Regards,
> > Manav
>
> > On Friday, April 27, 2012 1:37:34 PM UTC+5:30, Željko Filipin wrote:
>

AQUA

unread,
May 2, 2012, 12:41:43 AM5/2/12
to watir-...@googlegroups.com
Hello Bhavesh,
thanks for your reply. I have been using AutoIt only to handle the pop-ups. I guess I have not been able to make myself clear.
Actually the issue I m facing is I have to javascript events, on oncClick and other onBlur. For onClick I m using click_no_wait which works fine, i.e the AutoIt component clicks the ok button in case there is  a pop-up.

However, for onBlur event i m using fire_event('onBlur') available with WATIR for firing the java script. The issue I m facing is when I use fire_event, once the java script generates the pop-up, the execution gets stuck untill I manually click the ok button, unlike as incase of click_no_wait where once the pop-up is generated the execution flows to the next statement that Handles the pop-up using AutoIt.

Please assist.

Thanks and Regards,

Manav Gupta

Chuck van der Linden

unread,
May 2, 2012, 3:43:44 PM5/2/12
to watir-...@googlegroups.com
On Tuesday, May 1, 2012 9:41:43 PM UTC-7, AQUA wrote:
Hello Bhavesh,
thanks for your reply. I have been using AutoIt only to handle the pop-ups. I guess I have not been able to make myself clear.
Actually the issue I m facing is I have to javascript events, on oncClick and other onBlur. For onClick I m using click_no_wait which works fine, i.e the AutoIt component clicks the ok button in case there is  a pop-up.

However, for onBlur event i m using fire_event('onBlur') available with WATIR for firing the java script. The issue I m facing is when I use fire_event, once the java script generates the pop-up, the execution gets stuck untill I manually click the ok button, unlike as incase of click_no_wait where once the pop-up is generated the execution flows to the next statement that Handles the pop-up using AutoIt.

Please assist.

Thanks and Regards,

Manav Gupta

Try watir-webdriver, it has a different way (which might also be in watir3.0) of dealing with popups where you basically say "expect a popup to appear when I do this thing, when you see it click ok" (or whatever response you need such as yes or no etc) 

The code looks like this, where "browser.button(:value => 'Alert').click is the action that will cause the popup

  browser.alert do
    browser.button(:value => 'Alert').click
  end #=> 'the alert message' 

 the comment "=> 'the alert message' refers to the fact that this block of code will return the message displayed in the alert (in case you need to verify it) of course in the example above it just goes in the bit bucket, but if you had put something like the_message = in front of browser.alert, then you would have that message in a variable you could use later.

For more details on other alert types see here: http://watirwebdriver.com/javascript-dialogs/

just keep in mind that you will need to replace the  code inside the do loop with whatever action you want to perform that will generate the alert

AQUA

unread,
Jun 1, 2012, 4:44:01 AM6/1/12
to watir-...@googlegroups.com
Hi  Linden,
I tried out the example from watir -webdriver but I m still getting the following error message:

C:/Ruby187/lib/ruby/gems/1.8/gems/selenium-webdriver-2.21.2/lib/selenium/webdriver/remote/response.rb:52:in `assert_ok': Modal dialog present (Selenium::WebDriver::Error::UnhandledAlertError)
while following line is  executed

$browser.alert.exists?

Chuck van der Linden

unread,
Apr 10, 2013, 5:07:06 PM4/10/13
to watir-...@googlegroups.com
Did you read the entire thread?

When you say 'same error'  the same questions apply, such as 'are you using watir or watir-webdriver'

and 'show us the code you are trying to use, indicate where the error occurs, and what the error message (if any) is'



On Wednesday, April 10, 2013 1:13:04 AM UTC-7, prashant sharma wrote:
same error? what is the solution of it.

prashant sharma

unread,
Apr 11, 2013, 1:42:50 AM4/11/13
to watir-...@googlegroups.com
error resolve now


--
--
Before posting, please read http://watir.com/support. In short: search before you ask, be nice.
 
watir-...@googlegroups.com
http://groups.google.com/group/watir-general
watir-genera...@googlegroups.com
 
---
You received this message because you are subscribed to a topic in the Google Groups "Watir General" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/watir-general/faCno-Nk8aE/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to watir-genera...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages