Method: PageObject::Accessors#paragraph

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

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

adds three methods - one to retrieve the text of a paragraph, another to retrieve a paragraph element, and another to check the paragraph’s existence.

Examples:

paragraph(:title, :id => 'title')
# will generate 'title', 'title_element', and 'title?' methods

Parameters:

  • the (Symbol)

    name used for the generated methods

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

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

    • :class => Watir and Selenium

    • :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



935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
# File 'lib/page-object/accessors.rb', line 935

def paragraph(name, identifier={:index => 0}, &block)
  define_method(name) do
    return platform.paragraph_text_for identifier.clone unless block_given?
    self.send("#{name}_element").text
  end
  define_method("#{name}_element") do
    return call_block(&block) if block_given?
    platform.paragraph_for(identifier.clone)
  end
  define_method("#{name}?") do
    return call_block(&block).exists? if block_given?
    platform.paragraph_for(identifier.clone).exists?
  end
  alias_method "#{name}_paragraph".to_sym, "#{name}_element".to_sym
end