Tuesday, July 12, 2011

Firewatir vs Webdriver

I've moved from Firewatir to Webdriver recently and have noticed a few changes.  Specifically a change that halted one of my scripts and took a little prodding for a workaround when it was simply clicking links.

I have a Ruby script that opens a website, reads data, and if it's not a file I currently own it downloads it.  Two links, one opens a span and another is the download link - both have onclick javascript events.

In Firewatir to open the span or download the file, just click.

browser.link(:xpath =>"//someDiv[@id='siteLink']/xpath/to/link/a").click


This worked no problem until I tried Webdriver.  Now the page would only center on the span containing the link, but it would not open or start the download.

Doing some Google searching, I came across a Stackoverflow answer from the awesome Watir guru Željko Filipin.  Seriously, Zeljko, you rock.  For Webdriver the correct way to get these links to register is to directly fire the javascript event.

In Webdriver,

browser.link(:xpath =>"//someDiv[@id='siteLink']/xpath/to/link/a").fire_event "onclick"


Why there is a difference I'm not sure.  But this change allowed my script to use Webdriver and get back up and running.  It was a bit frustrating since everything had worked right for so long, and testing regular links worked just fine but I'm just glad to be able to use Webdriver with Firefox and get moving again.

No comments:

Post a Comment