Class: Capybara::Driver::Selenium::Node

Inherits:
Node
  • Object
show all
Defined in:
lib/capybara/driver/selenium_driver.rb

Instance Attribute Summary

Attributes inherited from Node

#driver, #node

Instance Method Summary collapse

Methods inherited from Node

#initialize, #path, #trigger

Methods included from Searchable

#all, #find, #find_button, #find_by_id, #find_field, #find_link

Constructor Details

This class inherits a constructor from Capybara::Node

Instance Method Details

#[](name) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/capybara/driver/selenium_driver.rb', line 9

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

#clickObject



60
61
62
# File 'lib/capybara/driver/selenium_driver.rb', line 60

def click
  node.click
end

#drag_to(element) ⇒ Object



64
65
66
# File 'lib/capybara/driver/selenium_driver.rb', line 64

def drag_to(element)
  node.drag_and_drop_on(element.node)
end

#select(option) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/capybara/driver/selenium_driver.rb', line 38

def select(option)
  option_node = node.find_element(:xpath, ".//option[normalize-space(text())=#{Capybara::XPath.escape(option)}]") || node.find_element(:xpath, ".//option[contains(.,#{Capybara::XPath.escape(option)})]")
  option_node.select
rescue 
  options = node.find_elements(:xpath, "//option").map { |o| "'#{o.text}'" }.join(', ')
  raise Capybara::OptionNotFound, "No such option '#{option}' in this select box. Available options: #{options}"
end

#set(value) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/capybara/driver/selenium_driver.rb', line 27

def set(value)
  if tag_name == 'input' and type == 'radio'
    node.click
  elsif tag_name == 'input' and type == 'checkbox'
    node.click if node.attribute('checked') != value
  elsif tag_name == 'textarea' or tag_name == 'input'
    node.clear
    node.send_keys(value.to_s)
  end
end

#tag_nameObject



68
69
70
# File 'lib/capybara/driver/selenium_driver.rb', line 68

def tag_name
  node.tag_name
end

#textObject



5
6
7
# File 'lib/capybara/driver/selenium_driver.rb', line 5

def text
  node.text
end

#unselect(option) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/capybara/driver/selenium_driver.rb', line 46

def unselect(option)
  if node['multiple'] != 'multiple'
    raise Capybara::UnselectNotAllowed, "Cannot unselect option '#{option}' from single select box."
  end

  begin
    option_node = node.find_element(:xpath, ".//option[normalize-space(text())=#{Capybara::XPath.escape(option)}]") || node.find_element(:xpath, ".//option[contains(.,#{Capybara::XPath.escape(option)})]")
    option_node.clear
  rescue
    options = node.find_elements(:xpath, "//option").map { |o| "'#{o.text}'" }.join(', ')
    raise Capybara::OptionNotFound, "No such option '#{option}' in this select box. Available options: #{options}"
  end
end

#valueObject



19
20
21
22
23
24
25
# File 'lib/capybara/driver/selenium_driver.rb', line 19

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

#visible?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/capybara/driver/selenium_driver.rb', line 72

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