Method: PageObject::Accessors#button

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

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

adds three methods - one to click a button, another to return the button element, and another to check the button’s existence.

Examples:

button(:purchase, :id => 'purchase')
# will generate 'purchase', 'purchase_element', and 'purchase?' methods

Parameters:

  • the (Symbol)

    name used for the generated methods

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

    how we find a button.

  • optional

    block to be invoked when element method is called



458
459
460
461
462
463
464
# File 'lib/page-object/accessors.rb', line 458

def button(name, identifier={:index => 0}, &block)
  standard_methods(name, identifier, 'button_for', &block)
  define_method(name) do
    return platform.click_button_for identifier.clone unless block_given?
    self.send("#{name}_element").click
  end
end