Skip to content

2 Defining Elements

Justin Watts edited this page May 26, 2017 · 3 revisions

Ferris exposes 2 methods element and elements, to use for creating Watir elements. The methods both take a symbol and a block for input. We give you full access to the Watir API by exposing the Watir::Browser as browser.

class Foo < Ferris::Page
  element(:foo) { browser.text_element(id: 'foo') }
end
$ Foo.new.foo.class
=> Watir::TextField

As a result, there are no default actions for any element defined in Ferris. You have to explicitly call foo.text or foo.set 'bar' if you want to use the element. It also means that you can use any of the various ways that Watir allows you to locate methods without restriction.

Another powerful feature is the ability to get a collection of elements by pluralizing the name of the element type.

class Foo < Ferris::Core
  elements(:bars) { browser.divs(class: 'bar') }
end
$ Foo.new.bars.class
=> Watir::DivCollection

Clone this wiki locally