Class: Capybara::Grid::Node

Inherits:
Driver::Node
  • Object
show all
Defined in:
lib/grid/extensions/capybara/node.rb

Instance Method Summary collapse

Instance Method Details

#[](name) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/grid/extensions/capybara/node.rb', line 6

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

#clickObject



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

def click
  resynchronize { native.click }
end

#drag_to(element) ⇒ Object



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

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

#find(locator) ⇒ Object



72
73
74
# File 'lib/grid/extensions/capybara/node.rb', line 72

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

#select_optionObject



37
38
39
# File 'lib/grid/extensions/capybara/node.rb', line 37

def select_option
  resynchronize { native.select }
end

#selected?Boolean Also known as: checked?

Returns:

  • (Boolean)


65
66
67
68
# File 'lib/grid/extensions/capybara/node.rb', line 65

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

#set(value) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/grid/extensions/capybara/node.rb', line 24

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



56
57
58
# File 'lib/grid/extensions/capybara/node.rb', line 56

def tag_name
  native.tag_name
end

#textObject



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

def text
  native.text
end

#unselect_optionObject



41
42
43
44
45
46
# File 'lib/grid/extensions/capybara/node.rb', line 41

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



16
17
18
19
20
21
22
# File 'lib/grid/extensions/capybara/node.rb', line 16

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)


60
61
62
63
# File 'lib/grid/extensions/capybara/node.rb', line 60

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