Method: PageObject::Accessors#text_field

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

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

adds four methods to the page object - one to set text in a text field, another to retrieve text from a text field, another to return the text field element, another to check the text field’s existence.

Examples:

text_field(:first_name, :id => "first_name")
# will generate 'first_name', 'first_name=', 'first_name_element',
# 'first_name?' methods

Parameters:

  • the (String)

    name used for the generated methods

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

    how we find a text field.

  • optional

    block to be invoked when element method is called



196
197
198
199
200
201
202
203
204
205
206
# File 'lib/page-object/accessors.rb', line 196

def text_field(name, identifier={:index => 0}, &block)
  standard_methods(name, identifier, 'text_field_for', &block)
  define_method(name) do
    return platform.text_field_value_for identifier.clone unless block_given?
    self.send("#{name}_element").value
  end
  define_method("#{name}=") do |value|
    return platform.text_field_value_set(identifier.clone, value) unless block_given?
    self.send("#{name}_element").value = value
  end
end