Module: Capybara::Searchable

Included in:
Node, Session
Defined in:
lib/capybara/searchable.rb

Instance Method Summary collapse

Instance Method Details

#all(*args) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/capybara/searchable.rb', line 24

def all(*args)
  options = if args.last.is_a?(Hash) then args.pop else {} end
  if args[1].nil?
    kind, locator = Capybara.default_selector, args.first
  else
    kind, locator = args
  end
  locator = XPath.from_css(locator) if kind == :css

  results = all_unfiltered(locator)

  if options[:text]
    results = results.select { |n| n.text.match(options[:text]) }
  end

  if options[:visible] or Capybara.ignore_hidden_elements
    results = results.select { |n| n.visible? }
  end

  results
end

#find(*args) ⇒ Object



3
4
5
# File 'lib/capybara/searchable.rb', line 3

def find(*args)
  all(*args).first
end

#find_button(locator) ⇒ Object



16
17
18
# File 'lib/capybara/searchable.rb', line 16

def find_button(locator)
  find(:xpath, XPath.button(locator))
end

#find_by_id(id) ⇒ Object



20
21
22
# File 'lib/capybara/searchable.rb', line 20

def find_by_id(id)
  find(:css, "##{id}")
end

#find_field(locator) ⇒ Object Also known as: field_labeled



7
8
9
# File 'lib/capybara/searchable.rb', line 7

def find_field(locator)
  find(:xpath, XPath.field(locator))
end


12
13
14
# File 'lib/capybara/searchable.rb', line 12

def find_link(locator)
  find(:xpath, XPath.link(locator))
end