click a javascript dialog window in Firefox

M

Mario Ruiz

Hi,
I'm trying to click a dialog box in Firefox but all the code I found is
not working.
I have watir and firewatir 1.6.5

Thanks
 
J

Jesús Gabriel y Galán

Hi,
I'm trying to click a dialog box in Firefox but all the code I found is
not working.
I have watir and firewatir 1.6.5

Firewatir::Firefox has a method startClicker that does that:

$ ri startClicker

---------------------------------------- FireWatir::Firefox#startClicker
startClicker(button, waitTime = 1, userInput = nil, text = nil)
------------------------------------------------------------------------
Description:

Tells FireWatir to click javascript button in case one comes
after performing some action on an element. Matches
text of pop up with one if supplied as parameter. If text
matches clicks the button else stop script execution until
pop up is dismissed by manual intervention.

Input:

button - JavaScript button to be clicked. Values can be OK or Cancel
waitTime - Time to wait for pop up to come. Not used just
for compatibility with Watir.
userInput - Not used just for compatibility with Watir
text - Text that should appear on pop up.

What this really does underneath is to change the window.alert method
for one that returns what you tell it to. It doesn't really open a
window anymore.

I've used this successfully once.

Hope this helps,

Jesus.
 
M

Mario Ruiz

But the thing is... if you click first.. ff keeps waiting and doesn't
return the control to ruby so in theory the only way to do it is call
startClicker first and then click the button... but it's not working
properly since what it is doing is just closing the JS window but not
clicking on the button as you can see in this example:

require "firewatir"
$ff = FireWatir::Firefox.new() #create an object to drive the browser
$ff.goto("http://w3schools.com/js/tryit_view.asp?filename=tryjs_confirm")
$ff.startClicker( "OK", 4)
$ff.button:)value,"Show a confirm box").click
sleep 3
$ff.close()
 
J

Jesús Gabriel y Galán

But the thing is... if you click first.. ff keeps waiting and doesn't
return the control to ruby so in theory the only way to do it is call
startClicker first and then click the button... but it's not working
properly since what it is doing is just closing the JS window but not
clicking on the button as you can see in this example:

require "firewatir"
$ff =3D FireWatir::Firefox.new() =A0#create an object to drive the browse= r
")
$ff.startClicker( "OK", 4)
$ff.button:)value,"Show a confirm box").click
sleep 3
$ff.close()

I don't know if you have other example that does something in the page
when OK is clicked.
What startClicker does, is to override the window.alert function with
a function that returns OK, so really no popup is open at all.

Jesus.
 
J

Jesús Gabriel y Galán

2010/8/13 Jes=FAs Gabriel y Gal=E1n said:
I don't know if you have other example that does something in the page
when OK is clicked.
What startClicker does, is to override the window.alert function with
a function that returns OK, so really no popup is open at all.

It also does the same with the confirm button, so your example should
work. I've tested it and it works (debugging with Firebug I see that
the call r =3D confirm.. returns true).

Jesus.
 
J

Jesús Gabriel y Galán

So there is no way to click the buttons on a javascript window

Inside Firewatir no, but why do you really need that? Your javascript
code will work as if the user had pressed the OK or the cancel button,
so everything should continue executing normally.

Jesus.
 
M

Mario Ruiz

Because, in some cases the page is doing different things depending what
I'm selecting... for example, the window says: do you want to go to
www.google.com? and the options: Yes, No
 
J

Jesús Gabriel y Galán

Because, in some cases the page is doing different things depending what
I'm selecting... for example, the window says: do you want to go to
www.google.com? and the options: Yes, No

But then you can automate to one option or the other with
startClicker("OK") or startClicker("cancel") (or maybe "Cancel", I'm
not sure)

Jesus.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top