Another possible solution for popup window handling

143 views
Skip to first unread message
Message has been deleted
Message has been deleted
Message has been deleted

George

unread,
Mar 3, 2010, 7:21:17 PM3/3/10
to Watir General
Hello all,

I was checking out the various solutions presented at
http://wiki.openqa.org/display/WTR/JavaScript+Pop+Ups. I found
another
solution some time ago that isn't listed there. You'll need AutoIt
installed. I'll present it here, and if you think it might help,
please feel free to add it to the list:

First, create a file called 'popup_closer.rb' and add the following
code:

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

require 'win32ole'

begin

autoit = WIN32OLE.new('AutoItX3.Control')
loop do
autoit.ControlClick("Windows Internet Explorer",'', 'OK')
autoit.ControlClick("Security Information",'', '&Yes')
autoit.ControlClick("Security Alert",'', '&Yes')
autoit.ControlClick("Security Warning",'', 'Yes')
autoit.ControlClick("Message from webpage",'', 'OK')
sleep 3
end

rescue Exception => e
puts e

end

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

Next, add the following to your working script:

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

@pid = Process.create(
:app_name => 'ruby popup_closer.rb',
:creation_flags => Process::DETACHED_PROCESS
).process_id
at_exit{ Process.kill(9,@pid) }

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

While the script is running, this will continue to check for any
popups and click OK. You can always change the options to "No",
"Cancel", etc.

If you want to kill the process earlier, remove the last line and
just
type: Process.kill(9,@pid).

HTH,

George

Željko Filipin

unread,
Mar 4, 2010, 4:14:40 AM3/4/10
to watir-...@googlegroups.com
On Thu, Mar 4, 2010 at 1:16 AM, George <george....@gmail.com> wrote:
> I was checking out the various solutions presented at
> http://wiki.openqa.org/display/WTR/JavaScript+Pop+Ups. I found another
> solution some time ago that isn't listed there. You'll need AutoIt
> installed. I'll present it here, and if you think it might help,
> please feel free to add it to the list:

George,

Please add the code to the page yourself. It is a wiki page. Please let me know if you need help with that. It should not take more than a few minutes, even if you have to create an account.

Željko
--
watir.com - community manager
pledgie.com/campaigns/2982 - donate to Watir
watirpodcast.com - host
testingpodcast.com - audio podcasts on software testing. all of them

George

unread,
Mar 4, 2010, 12:04:10 PM3/4/10
to Watir General
Hi Željko,

Sorry about that! I added this solution to the wiki. It would be nice
to know if it works well for others. I couldn't seem to get any of the
other suggestions to work for me.

-George


On Mar 4, 1:14 am, Željko Filipin <zeljko.fili...@wa-research.ch>
wrote:

Željko Filipin

unread,
Mar 5, 2010, 4:20:41 AM3/5/10
to watir-...@googlegroups.com
On Thu, Mar 4, 2010 at 6:04 PM, George <george....@gmail.com> wrote:
> I added this solution to the wiki.

Thanks!


> It would be nice
> to know if it works well for others. I couldn't seem to get any of the
> other suggestions to work for me.

If it works for you, it could help somebody else. Personally, I always insist that the application does not have pop-ups. I just refuse to automate tests that have to deal with popups (exceptions are file uploads and div popups.). It has worked for me for the past five years.

Željko

Shlomit Gazit

unread,
Mar 16, 2010, 8:27:49 PM3/16/10
to Watir General
George,
Your solution is the only one that is working for me for handling
popups. Thank you!
Minor thing I couldnt figure out:
Each time that there is a popup, ruby.exe process is being created. At
the end of the test, I have lots of ruby.exe processes running, and if
I have multiple testes running one after another, I have even more
ruby.exe processes alive.

at_exit is not killing them, and if I do only: Process.kill(9,@pid),
then the popup is not closing, maybe because the process is being
killed before the click.

Any idea?

On Mar 5, 2:20 am, Željko Filipin <zeljko.fili...@wa-research.ch>
wrote:

George

unread,
Mar 23, 2010, 8:07:52 PM3/23/10
to Watir General
Hi, sorry for the late response. I'm not sure why it's doing that. The
process should end at the end of your script. If the script crashes
while you're running it, there may have been a process still running
in the background. Sorry I can't be of better assistance.

-George

On Mar 16, 5:27 pm, Shlomit Gazit <shlomitpatr...@gmail.com> wrote:
> George,
> Your solution is the only one that is working for me for handling
> popups. Thank you!
> Minor thing  I couldnt figure out:
> Each time that there is a popup, ruby.exe process is being created. At
> the end of the test, I have lots of ruby.exe processes running, and if
> I have multiple testes running one after another, I have even more
> ruby.exe processes alive.
>
> at_exit is not killing them, and if I do only: Process.kill(9,@pid),
> then the popup is not closing, maybe because the process is being
> killed before the click.
>
> Any idea?
>
> On Mar 5, 2:20 am, Željko Filipin <zeljko.fili...@wa-research.ch>
> wrote:
>
>
>
> > On Thu, Mar 4, 2010 at 6:04 PM, George <george.sand...@gmail.com> wrote:
> > > I added this solution to the wiki.
>
> > Thanks!
>
> > > It would be nice
> > > to know if it works well for others. I couldn't seem to get any of the
> > > other suggestions to work for me.
>
> > If it works for you, it could help somebody else. Personally, I always

> > insist that the application does not havepop-ups. I just refuse to automate

Reply all
Reply to author
Forward
0 new messages