Method: PageObject::Accessors#elements

Defined in:
lib/page-object/accessors.rb

#elements(name, tag, identifier = {:index => 0}, &block) ⇒ Object

adds a method to return a collection of generic Element objects for a specific tag.

Examples:

elements(:title, :header, :id => 'title')
# will generate ''title_elements'

Parameters:

  • the (Symbol)

    name used for the generated methods

  • the (Symbol)

    name of the tag for the element

  • identifier (Hash) (defaults to: {:index => 0})

    how we find an element. You can use a multiple parameters by combining of any of the following except xpath. The valid keys are:

    • :class => Watir and Selenium

    • :css => Selenium only

    • :id => Watir and Selenium

    • :index => Watir and Selenium

    • :name => Watir and Selenium

    • :xpath => Watir and Selenium

  • optional

    block to be invoked when element method is called



1255
1256
1257
1258
1259
1260
# File 'lib/page-object/accessors.rb', line 1255

def elements(name, tag, identifier={:index => 0}, &block)
  define_method("#{name}_elements") do
    return call_block(&block) if block_given?
    platform.elements_for(tag, identifier.clone)
  end
end