Module: CapybaraExtensions::Locators

Included in:
Finders, Matchers
Defined in:
lib/capybara-extensions/locators.rb

Overview

Locators for xpath.

Instance Method Summary collapse

Instance Method Details

#image_locator(options) ⇒ String

Builds a locator via the given src or alt.

Parameters:

  • options (Hash)

    must pass a hash containing src and/or alt to match against.

Returns:

  • (String)

    string formatted for finding an attribute with xpath.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/capybara-extensions/locators.rb', line 9

def image_locator(options)
  locator = String.new

  if options[:src]
    if Regexp === options[:src] && image = _find_image_with_regex(options[:src])
      locator.concat("[@src='#{image}']")
    else options[:src]
      locator.concat "[@src='#{options[:src]}']"
    end
  end

  locator.concat "[@alt='#{options[:alt]}']" if options[:alt]
  locator
end

#meta_tag_locator(name, content) ⇒ String

Builds a locator via the given name and content.

Returns:

  • (String)

    string formatted for finding a meta tag with xpath.



30
31
32
33
34
35
# File 'lib/capybara-extensions/locators.rb', line 30

def meta_tag_locator(name, content)
  locator = String.new
  locator.concat "[@name='#{name}']"
  locator.concat "[@content='#{content}']"
  locator
end