# How to handle java script pop ups?

**URL:** <https://www.ruby-forum.com/t/how-to-handle-java-script-pop-ups/128029>\
**Category:** Ruby\
**Created:** [February 4, 2008, 11:54am UTC](https://www.ruby-forum.com/t/how-to-handle-java-script-pop-ups/128029 "2008-02-04T11:54:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pradeepta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee59a6/32.png) [@pradeepta](https://www.ruby-forum.com/u/pradeepta)\
**Post date:** [February 4, 2008, 11:54am UTC](https://www.ruby-forum.com/t/how-to-handle-java-script-pop-ups/128029/1 "2008-02-04T11:54:27Z")

</div>

How can I access java script pop ups using ruby ? I want to access the  
alert message as well as click the button of pop up boxes . How can I do  
that ? Anybody help ??

---

<div class="post-metadata">

**Author:** ![pradeepta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee59a6/32.png) [@pradeepta](https://www.ruby-forum.com/u/pradeepta)\
**Post date:** [February 4, 2008, 10:46pm UTC](https://www.ruby-forum.com/t/how-to-handle-java-script-pop-ups/128029/2 "2008-02-04T22:46:31Z")

</div>

Pradeepta S. wrote:

> How can I access java script pop ups using ruby ? I want to access the  
> alert message as well as click the button of pop up boxes . How can I do  
> that ? Anybody help ??

I don’t think you can. javascript is part of a software program  
variously named: IE, Firefox, Safari, etc. that executes on a user’s  
computer. It’s hard to tell what type of program that you want to use  
to control the javascript execution:

1. A program running on the user’s computer where the web browser is  
executing the javascript
2. a program on a remote server.

With 2), you can’t affect something that is executing in the user’s  
browser. A program on a server can decide what to send to the client  
browser, but once the client browser starts executing the javascript,  
the javascript program decides what will happen from then on–not your  
program on the server.

With 1), I think it is probably possible, but you would have to somehow  
use ruby to control how a software program is executing, i.e. the  
browser. That would require that your ruby program open communication  
with the browser and then use it’s API to affect how the browser  
executes the javascript. I doubt whether the API provides such fine  
grained control like that, and if it did, you would probably have to  
study the API for years before you could figure out how to do that.

---

<div class="post-metadata">

**Author:** ![pradeepta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee59a6/32.png) [@pradeepta](https://www.ruby-forum.com/u/pradeepta)\
**Post date:** [February 4, 2008, 11:45pm UTC](https://www.ruby-forum.com/t/how-to-handle-java-script-pop-ups/128029/3 "2008-02-04T23:45:33Z")

</div>

If you want to do a fair amount of hacking you could try playing  
around with ruby-spidermonkey, it’s a bunch of ruby bindings for  
firefox’s javascript interpreter, (code named SpiderMonkey.)

[http://code.google.com/p/ruby-spidermonkey/](http://code.google.com/p/ruby-spidermonkey/)

Aside from that, I’ve had a hard time finding good support for JS in  
ruby. Maybe somebody on the board has had better results?

---

<div class="post-metadata">

**Author:** ![pradeepta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee59a6/32.png) [@pradeepta](https://www.ruby-forum.com/u/pradeepta)\
**Post date:** [February 5, 2008, 3:47am UTC](https://www.ruby-forum.com/t/how-to-handle-java-script-pop-ups/128029/4 "2008-02-05T03:47:22Z")

</div>

Hi Pradeep,  
I assume you are trying to automate IE or FF browser, if not  
please ignore.

If you are I believe this should help you.  
[http://wiki.openqa.org/display/WTR/Pop+Ups](http://wiki.openqa.org/display/WTR/Pop+Ups)

Regards,  
Manish

Excerpts from Pradeepta S.'s message of Mon Feb 04 16:24:21 +0530  
2008:
