Skip to content

Support for both watir webdriver and selenium webdriver

cheezy edited this page Jul 29, 2011 · 3 revisions

The page-object gem can use either watir-webdriver or selenium-webdriver as the underlying gem to drive the browser. The way you choose which driver to use is by passing it into the constructor of your PageObject.

browser = Watir::Browser.new :firefox
registration_page = RegistrationPage.new(browser)

or

browser = Selenium::Webdriver.for :firefox
registration_page = RegistrationPage.new(browser)

In order to make this work seamlessly the page-object gem had to add capabilities found in one driver and not in the other.

Locating elements

There were differences in the way Watir and Selenium would allow you to locate elements on a page. We added functionality to page-object to eliminate those differences. Here are a few notable ones.

  • Watir has always allowed you to provide multiple locators when identifying an element on a page. Selenium only allows you to provide one locator. With page-object you can now use multiple parameters when using Selenium.
  • Watir provides the ability to use :index when locating an element. Selenium did not have this capability. With page-object you can now use :index when using Selenium.
  • In Selenium you could not find a link by :href while this ability existed in Watir. With page-object on Selenium you can now use :href when identifying a link.
  • Watir supports finding a hidden field by :text. This ability did not exist in Selenium. With page-object you can find a hidden field by :text when using Selenium.
  • Watir did not support finding div, span, table, table data, ordered lists, unordered lists and list items by :name. Selenium had this ability. With page-object you can now find these elements using :name.