Scott Hanselman

A Very Poor Man's Vonage Web Service using Watir

July 2, '06 Comments [13] Posted in Ruby | Watir
Sponsored By

Folks keep calling after 9pm and waking the baby. We use Vonage, and I really wish they had a feature where I could indicate "do not call" times. Alas, they don't. So, then I wished for a Vonage Web Service. Nope.

So, instead here's a Watir script, recorded with a early version of Michael Kelly and John Hann's port of WatirMaker to Ruby (via "ruby watirmaker.rb > myscript.rb") then edited to taste.

#Enable Instant Forward to Voice Mail
require 'watir'
include Watir

ie = IE.new
ie.goto( 'http://www.vonage.com/' )

ie.text_field( :name, 'username' ).set( 'username' )
ie.text_field( :name, 'password' ).set( 'password' )
ie.button( :name, 'submit' ).click

ie.link(:text,"Features").click

ie.button( :name, 'callForwardingButton' ).click

ie.select_list( :name, 'callForwardingSeconds' ).select( 'Instantly' )
ie.text_field( :name, 'singleAddress' ).set( '15035551234' )

ie.button(:value,'Enable').click

ie.link(:text,"Log Out").click
ie.close

And the disable...

require 'watir'
include Watir

ie = IE.new
ie.goto( 'http://www.vonage.com/' )

ie.text_field( :name, 'username' ).set( 'username')
ie.text_field( :name, 'password' ).set( 'password' )
ie.button( :name, 'submit' ).click

ie.link(:text,"Features").click

ie.button( :name, 'callForwardingButton' ).click

ie.button(:value,'Disable').click

ie.link(:text,"Log Out").click
ie.close

These now run on a schedule in my house using the Windows Scheduler. If you run them like 'ruby enable.rb -b' they run in the background and you'll never see Internet Explorer.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web
Sunday, July 02, 2006 7:48:35 AM UTC
Awesome and amazing hack. I'm convinced now most anything can be mashed, smashed, hacked. I love it. My baby's due the 26th of July. Could make use of this soon.

Thanks, Scott.
Sunday, July 02, 2006 8:22:01 AM UTC
Awesome. On the topic of ruby, have you seen www.sapphiresteel.com? Ruby goodness in the comfort of vs.net
street
Monday, July 03, 2006 12:37:25 AM UTC
James - thanks for the pointer! Blogged!
Scott Hanselman
Monday, July 03, 2006 1:08:20 PM UTC
The watirmaker.rb link does not seem to work...
Justin
Monday, July 03, 2006 4:23:58 PM UTC
NICE!
This is one of those times where I just had to slap my head and think "Why in the hell didn't I think of that?"
Thanks, Scott. I'll be putting this one to good use.

Monday, July 03, 2006 8:48:18 PM UTC
Fixed.
Scott Hanselman
Monday, July 03, 2006 9:23:38 PM UTC
Sleek, Simple and Superb.
you may want to give yourself a 5 minute latency, as I doubt the change is real time.

Sat
Satish Balusa
Wednesday, July 05, 2006 6:54:50 PM UTC
VoicePulse has the Do Not Disturb feature, and it will come in very handy when our newborn arrives.

Hard to believe Vonage hasn't implemented this yet. Nice workaround, though.
Neill
Sunday, July 16, 2006 11:18:05 PM UTC
I (finally) got around to trying this. I'm getting an exception when it goes to click on the callForwardingButton. It says it can't find it. Any suggestions? I looked in the HTML of the page, and its there. Here's the actual error message...

c:/ruby/lib/ruby/gems/1.8/gems/watir-1.4.1/./watir.rb:1928:in `assert_exists': U
nable to locate object, using name and callForwardingButton (Watir::Exception::U
nknownObjectException)
from c:/ruby/lib/ruby/gems/1.8/gems/watir-1.4.1/./watir.rb:2009:in `clic
k'
from C:/Documents and Settings/Tim/Desktop/test2.rb:24
Tim Coker
Tuesday, July 18, 2006 4:54:58 AM UTC
Tim, not sure what to tell you. It works here. That error says there's no button on the page called "callForwardingButton."

Is there?

I do know that on Firefox the Enable button is named "Save Changes." Vonage is doing some kind of sniffing.
Scott Hanselman
Tuesday, July 18, 2006 6:57:37 PM UTC
I looked at the page that was left open after the script crashed, and in the source, the button exists. It also appears the the script ALWAYS waits until the page is 100% loaded before continuing. If this is the case, then there's no reason I can think of that could cause it to fail.... I recorded the script myself.

I was running it on my laptop downstairs (older box runnin win2k), and I don't think I tried it on the computer upstairs (MCE2k5). Would the version of IE make a difference? I'll try to play with it some more tonight. On the computer upstairs as well as my work laptop. I can't play with it here as our admins are a bunch of nazis and have vonage websensed.
Tim Coker
Tuesday, July 18, 2006 7:09:10 PM UTC
Try using my script and not a recorded one...
Scott Hanselman
Wednesday, July 19, 2006 2:51:49 AM UTC
I'm not sure quite what this means, but instead of
ie.link(:text,"Features").click
the recorded script wound up with
ie.document.all[ '85' ].click

They both go through to the features page, but when it used the document.all method, it couldn't find the callForwardingButton.

Either way, it works now. Thanks!

(For the record, I started with your script, but didn't have watir installed right, so I gave up on that initially. I wanted to automate something slightly different, so I recorded my own.)
Tim Coker
Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.