Class: Capybara::Selenium::Node

Inherits:
Driver::Node show all
Defined in:
lib/capybara/selenium/node.rb

Instance Attribute Summary

Attributes inherited from Driver::Node

#driver, #native

Instance Method Summary (collapse)

Methods inherited from Driver::Node

#initialize, #inspect, #path, #trigger

Constructor Details

This class inherits a constructor from Capybara::Driver::Node

Instance Method Details

- (Object) [](name)



6
7
8
9
10
# File 'lib/capybara/selenium/node.rb', line 6

def [](name)
  native.attribute(name.to_s)
rescue Selenium::WebDriver::Error::WebDriverError
  nil
end

- (Object) click



44
45
46
# File 'lib/capybara/selenium/node.rb', line 44

def click
  resynchronize { native.click }
end

- (Object) drag_to(element)



48
49
50
# File 'lib/capybara/selenium/node.rb', line 48

def drag_to(element)
  resynchronize { native.drag_and_drop_on(element.native) }
end

- (Object) find(locator)



68
69
70
# File 'lib/capybara/selenium/node.rb', line 68

def find(locator)
  native.find_elements(:xpath, locator).map { |n| self.class.new(driver, n) }
end

- (Object) select_option



33
34
35
# File 'lib/capybara/selenium/node.rb', line 33

def select_option
  resynchronize { native.select }
end

- (Boolean) selected? Also known as: checked?



61
62
63
64
# File 'lib/capybara/selenium/node.rb', line 61

def selected?
  selected = native.selected?
  selected and selected != "false"
end

- (Object) set(value)



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/capybara/selenium/node.rb', line 20

def set(value)
  if tag_name == 'input' and type == 'radio'
    click
  elsif tag_name == 'input' and type == 'checkbox'
    click if value ^ native.attribute('checked').to_s.eql?("true")
  elsif tag_name == 'textarea' or tag_name == 'input'
    resynchronize do
      native.clear
      native.send_keys(value.to_s)
    end
  end
end

- (Object) tag_name



52
53
54
# File 'lib/capybara/selenium/node.rb', line 52

def tag_name
  native.tag_name.downcase
end

- (Object) text



2
3
4
# File 'lib/capybara/selenium/node.rb', line 2

def text
  native.text
end

- (Object) unselect_option



37
38
39
40
41
42
# File 'lib/capybara/selenium/node.rb', line 37

def unselect_option
  if select_node['multiple'] != 'multiple' and select_node['multiple'] != 'true'
    raise Capybara::UnselectNotAllowed, "Cannot unselect option from single select box."
  end
  resynchronize { native.toggle } if selected?
end

- (Object) value



12
13
14
15
16
17
18
# File 'lib/capybara/selenium/node.rb', line 12

def value
  if tag_name == "select" and self[:multiple] and not self[:multiple] == "false"
    native.find_elements(:xpath, ".//option").select { |n| n.selected? }.map { |n| n[:value] || n.text }
  else
    native[:value]
  end
end

- (Boolean) visible?



56
57
58
59
# File 'lib/capybara/selenium/node.rb', line 56

def visible?
  displayed = native.displayed?
  displayed and displayed != "false"
end