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

#[](name) ⇒ Object



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

#clickObject



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

def click
  resynchronize { native.click }
end

#drag_to(element) ⇒ Object



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

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

#find(locator) ⇒ Object



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

#select_optionObject



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

def select_option
  resynchronize { native.select }
end

#selected?Boolean Also known as: checked?

Returns:

  • (Boolean)


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

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

#set(value) ⇒ Object



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

#tag_nameObject



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

def tag_name
  native.tag_name.downcase
end

#textObject



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

def text
  native.text
end

#unselect_optionObject



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

#valueObject



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

#visible?Boolean

Returns:

  • (Boolean)


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

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