Module: CapybaraExtensions::Finders

Includes:
Locators
Defined in:
lib/capybara-extensions/finders.rb

Instance Method Summary collapse

Methods included from Locators

#image_locator, #meta_tag_locator

Instance Method Details

#find_article(args) ⇒ Capybara::Element Also known as: article

Find an HTML article based on the given arguments.

Parameters:

  • args (String)

    text contained within the article sought.

  • args (Object)

    the object whose article is sought.

Returns:

  • (Capybara::Element)

    the found element.



12
13
14
# File 'lib/capybara-extensions/finders.rb', line 12

def find_article(args)
  find_element('article', args)
end

#find_aside(args) ⇒ Capybara::Element Also known as: aside

Find an HTML aside based on the given arguments.

Parameters:

  • args (String)

    text contained within the aside sought.

  • args (Object)

    the object whose aside is sought.

Returns:

  • (Capybara::Element)

    the found element.



24
25
26
# File 'lib/capybara-extensions/finders.rb', line 24

def find_aside(args)
  find_element('aside', args)
end

Find an HTML footer based on the given arguments.

Parameters:

  • args (String)

    text contained within the footer sought.

  • args (Object)

    the object whose footer is sought.

Returns:

  • (Capybara::Element)

    the found element.



36
37
38
# File 'lib/capybara-extensions/finders.rb', line 36

def find_footer(args)
  find_element('footer', args)
end

#find_form(args) ⇒ Capybara::Element Also known as: form

Find an HTML form based on the given arguments.

Parameters:

  • args (String)

    text contained within the form sought.

  • args (Object)

    the object whose form is sought.

Returns:

  • (Capybara::Element)

    the found element.



48
49
50
# File 'lib/capybara-extensions/finders.rb', line 48

def find_form(args)
  find_element('form', args)
end

#find_header(args) ⇒ Capybara::Element Also known as: header

Find an HTML header based on the given arguments.

Parameters:

  • args (String)

    text contained within the header sought.

  • args (Object)

    the object whose header is sought.

Returns:

  • (Capybara::Element)

    the found element.



70
71
72
# File 'lib/capybara-extensions/finders.rb', line 70

def find_header(args)
  find_element('header', args)
end

#find_image(options = {}) ⇒ Capybara::Element

Find an HTML img based on the src and/or alt values.

Parameters:

  • options (Hash) (defaults to: {})

    Must pass a hash containing the src and/or alt of the image sought. You may pass a Regexp with src; however, this should be done sparingly, as CapybaraExtensions::Locators#image_locator will find and iterate over all images in the current scope.

Returns:

  • (Capybara::Element)

    the found element



59
60
61
62
# File 'lib/capybara-extensions/finders.rb', line 59

def find_image(options = {})
  raise "Must pass a hash containing 'src' or 'alt'" unless options.is_a?(Hash) && (options.has_key?(:src) || options.has_key?(:alt))
  find(:xpath, "//img#{image_locator(options)}")
end

#find_list_item(args) ⇒ Capybara::Element Also known as: list_item

Find an HTML li based on the given arguments.

Parameters:

  • args (String)

    text contained within the li sought.

  • args (Object)

    the object whose li is sought.

Returns:

  • (Capybara::Element)

    the found element.



82
83
84
# File 'lib/capybara-extensions/finders.rb', line 82

def find_list_item(args)
  find_element('li', args)
end

#find_navigation(args) ⇒ Capybara::Element Also known as: navigation

Find an HTML nav based on the given arguments.

Parameters:

  • args (String)

    text contained within the nav sought.

  • args (Object)

    the object whose nav is sought.

Returns:

  • (Capybara::Element)

    the found element.



94
95
96
# File 'lib/capybara-extensions/finders.rb', line 94

def find_navigation(args)
  find_element('nav', args)
end

#find_ordered_list(args) ⇒ Capybara::Element Also known as: ordered_list

Find an HTML ol based on the given arguments.

Parameters:

  • args (String)

    text contained within the ol sought.

  • args (Object)

    the object whose ol is sought.

Returns:

  • (Capybara::Element)

    the found element.



106
107
108
# File 'lib/capybara-extensions/finders.rb', line 106

def find_ordered_list(args)
  find_element('ol', args)
end

#find_paragraph(args) ⇒ Capybara::Element Also known as: paragraph

Find an HTML p based on the given arguments.

Parameters:

  • args (String)

    text contained within the p sought.

  • args (Object)

    the object whose p is sought.

Returns:

  • (Capybara::Element)

    the found element.



118
119
120
# File 'lib/capybara-extensions/finders.rb', line 118

def find_paragraph(args)
  find_element('p', args)
end

#find_row(args) ⇒ Capybara::Element Also known as: row

Find an HTML tr based on the given arguments.

Parameters:

  • args (String)

    text contained within the tr sought.

  • args (Object)

    the object whose tr is sought.

Returns:

  • (Capybara::Element)

    the found element.



130
131
132
# File 'lib/capybara-extensions/finders.rb', line 130

def find_row(args)
  find_element('tr', args)
end

#find_section(args) ⇒ Capybara::Element Also known as: section

Find an HTML section based on the given arguments.

Parameters:

  • args (String)

    text contained within the section sought.

  • args (Object)

    the object whose section is sought.

Returns:

  • (Capybara::Element)

    the found element.



142
143
144
# File 'lib/capybara-extensions/finders.rb', line 142

def find_section(args)
  find_element('section', args)
end

#find_table(args) ⇒ Capybara::Element Also known as: table

Find an HTML table based on the given arguments.

Parameters:

  • args (String)

    text contained within the table sought.

  • args (Object)

    the object whose table is sought.

Returns:

  • (Capybara::Element)

    the found element.



154
155
156
157
158
159
160
161
# File 'lib/capybara-extensions/finders.rb', line 154

def find_table(args)
  if String === args
    find_element('table', args)
  else
    row = find_row(args)
    row.find(:xpath, 'ancestor::table')
  end
end

#find_unordered_list(args) ⇒ Capybara::Element Also known as: unordered_list

Find an HTML ul based on the given arguments.

Parameters:

  • args (String)

    text contained within the ul sought.

  • args (Object)

    the object whose ul is sought.

Returns:

  • (Capybara::Element)

    the found element.



171
172
173
# File 'lib/capybara-extensions/finders.rb', line 171

def find_unordered_list(args)
  find_element('ul', args)
end

#first_article(args = nil) ⇒ Capybara::Element

Find the first HTML article on the page matching the given arguments. If no arguments are supplied, it will find the first article within your current scope.

Parameters:

  • args (String) (defaults to: nil)

    text contained within the article sought.

  • args (Object) (defaults to: nil)

    the object whose article is sought.

Returns:

  • (Capybara::Element)

    the found element.



183
184
185
# File 'lib/capybara-extensions/finders.rb', line 183

def first_article(args=nil)
  first_element('article', args)
end

#first_aside(args = nil) ⇒ Capybara::Element

Find the first HTML aside on the page matching the given arguments. If no arguments are supplied, it will find the first aside within your current scope.

Parameters:

  • args (String, Object) (defaults to: nil)

    if passed a string, the text contained within the aside sought; if passed an object, the object whose aside is sought.

Returns:

  • (Capybara::Element)

    the found element.



192
193
194
# File 'lib/capybara-extensions/finders.rb', line 192

def first_aside(args=nil)
  first_element('aside', args)
end

Find the first HTML footer on the page matching the given arguments. If no arguments are supplied, it will find the first footer within your current scope.

Parameters:

  • args (String, Object) (defaults to: nil)

    if passed a string, the text contained within the footer sought; if passed an object, the object whose footer is sought.

Returns:

  • (Capybara::Element)

    the found element.



201
202
203
# File 'lib/capybara-extensions/finders.rb', line 201

def first_footer(args=nil)
  first_element('footer', args)
end

#first_form(args = nil) ⇒ Capybara::Element

Find the first HTML form on the page matching the given arguments. If no arguments are supplied, it will find the first form within your current scope.

Parameters:

  • args (String, Object) (defaults to: nil)

    if passed a string, the text contained within the form sought; if passed an object, the object whose form is sought.

Returns:

  • (Capybara::Element)

    the found element.



210
211
212
# File 'lib/capybara-extensions/finders.rb', line 210

def first_form(args=nil)
  first_element('form', args)
end

#first_header(args = nil) ⇒ Capybara::Element

Find the first HTML header on the page matching the given arguments. If no arguments are supplied, it will find the first header within your current scope.

Parameters:

  • args (String, Object) (defaults to: nil)

    if passed a string, the text contained within the header sought; if passed an object, the object whose header is sought.

Returns:

  • (Capybara::Element)

    the found element.



219
220
221
# File 'lib/capybara-extensions/finders.rb', line 219

def first_header(args=nil)
  first_element('header', args)
end

#first_navigation(args = nil) ⇒ Capybara::Element

Find the first HTML nav on the page matching the given arguments. If no arguments are supplied, it will find the first nav within your current scope.

Parameters:

  • args (String, Object) (defaults to: nil)

    if passed a string, the text contained within the nav sought; if passed an object, the object whose nav is sought.

Returns:

  • (Capybara::Element)

    the found element.



228
229
230
# File 'lib/capybara-extensions/finders.rb', line 228

def first_navigation(args=nil)
  first_element('nav', args)
end

#first_ordered_list(args = nil) ⇒ Capybara::Element

Find the first HTML ol on the page matching the given arguments. If no arguments are supplied, it will find the first ol within your current scope.

Parameters:

  • args (String, Object) (defaults to: nil)

    if passed a string, the text contained within the ol sought; if passed an object, the object whose ol is sought.

Returns:

  • (Capybara::Element)

    the found element.



237
238
239
# File 'lib/capybara-extensions/finders.rb', line 237

def first_ordered_list(args=nil)
  first_element('ol', args)
end

#first_paragraph(args = nil) ⇒ Capybara::Element

Find the first HTML p on the page matching the given arguments. If no arguments are supplied, it will find the first p within your current scope.

Parameters:

  • args (String, Object) (defaults to: nil)

    if passed a string, the text contained within the p sought; if passed an object, the object whose p is sought.

Returns:

  • (Capybara::Element)

    the found element.



246
247
248
# File 'lib/capybara-extensions/finders.rb', line 246

def first_paragraph(args=nil)
  first_element('p', args)
end

#first_row(args = nil) ⇒ Capybara::Element

Find the first HTML tr on the page matching the given arguments. If no arguments are supplied, it will find the first tr within your current scope.

Parameters:

  • args (String, Object) (defaults to: nil)

    if passed a string, the text contained within the tr sought; if passed an object, the object whose tr is sought.

Returns:

  • (Capybara::Element)

    the found element.



255
256
257
# File 'lib/capybara-extensions/finders.rb', line 255

def first_row(args=nil)
  first_element('tr', args)
end

#first_section(args = nil) ⇒ Capybara::Element

Find the first HTML section on the page matching the given arguments. If no arguments are supplied, it will find the first section within your current scope.

Parameters:

  • args (String, Object) (defaults to: nil)

    if passed a string, the text contained within the section sought; if passed an object, the object whose section is sought.

Returns:

  • (Capybara::Element)

    the found element.



264
265
266
# File 'lib/capybara-extensions/finders.rb', line 264

def first_section(args=nil)
  first_element('section', args)
end

#first_table(args = nil) ⇒ Capybara::Element

Find the first HTML table on the page matching the given arguments. If no arguments are supplied, it will find the first table within your current scope.

Parameters:

  • args (String, Object) (defaults to: nil)

    if passed a string, the text contained within the table sought; if passed an object, the object whose table is sought.

Returns:

  • (Capybara::Element)

    the found element.



273
274
275
# File 'lib/capybara-extensions/finders.rb', line 273

def first_table(args=nil)
  first_element('table', args)
end

#first_unordered_list(args = nil) ⇒ Capybara::Element

Find the first HTML ul on the page matching the given arguments. If no arguments are supplied, it will find the first unordered list within your current scope.

Parameters:

  • args (String, Object) (defaults to: nil)

    if passed a string, the text contained within the ul sought; if passed an object, the object whose ul is sought.

Returns:

  • (Capybara::Element)

    the found element.



282
283
284
# File 'lib/capybara-extensions/finders.rb', line 282

def first_unordered_list(args=nil)
  first_element('ul', args)
end

#list_item_number(number) ⇒ Capybara::Element

When scoped to an ol or ul, find the first HTML li on the page matching the given arguments.

Parameters:

  • number (Integer)

    the nth li element sought.

Returns:

  • (Capybara::Element)

    the found element.



291
292
293
# File 'lib/capybara-extensions/finders.rb', line 291

def list_item_number(number)
  find_element_by_number('li', number)
end

#row_number(number) ⇒ Capybara::Element

When scoped to a table, find the first HTML tr on the page matching the given arguments. If passed a negative number, it will find the first tr from the bottom of the table (so row_number(-1) finds the last row in the table).

Parameters:

  • number (Integer)

    the nth tr element sought

Returns:

  • (Capybara::Element)

    the found element.



300
301
302
# File 'lib/capybara-extensions/finders.rb', line 300

def row_number(number)
  find_element_by_number('tr', number)
end