Take the 2-minute tour ×

One of the barriers (that as far as I know was never removed, but perhaps I'm mistaken and this was resolved a while ago?) to being able to have truly cross browser compatible tests with Watir and Firewatir is that Watir was originally designed to use One based indexing, while whoever created firewatir broke with that and made it Zero based.

While I'm sure there are good historical reasons for each decision, and I don't want to debate which is right, it's been a pain for testers trying to create scripts that run under each without any alteration since at the very least this affects identifying elements by :index, which is sometimes something you've no choice but to do.

I'm wondering if moving to Watir-Webdriver could create a more uniform platform?

Also do we have any reference to the differences between the latest Watir, and Watir-Webdriver? For example in a recent question here it came up that .value= is not implemented as a 'direct set without events' alternative to .set, and basically acts just the same as .set does.

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

The best solution to this problem would be for Watir 1.X to gain configurable indexing. I believe the majority of that work has already been done on Bret's zero-index branch, so it's just a question of someone picking that up and getting it out there.

When we were migrating to watir-webdriver, we added this monkey patch to help with this problem:

class Fixnum
  def as_index
    Config.webdriver? ? self - 1 : self

and then in our scripts:

browser.div(:index => 1.as_index)

Then when we were off Watir completely, it was a simple matter of grepping for as_index throughout the code base and decrement the indexes by one.

I've tried to document the major differences between Watir and watir-webdriver on this wiki page. I'm sure it's lacking, and if someone wants to improve it, that's very welcome of course :)

share|improve this answer
And in fact a selector to use zero or one based indexing is now in place in Watir 2.0.x –  Chuck van der Linden Nov 10 '11 at 16:52
add comment

Your Answer


