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, #value

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)
  end
rescue Selenium::WebDriver::Error::WebDriverError
  nil
end

#clickObject



52
53
54
# File 'lib/capybara/driver/selenium_driver.rb', line 52

def click
  node.click
end

#drag_to(element) ⇒ Object



56
57
58
# File 'lib/capybara/driver/selenium_driver.rb', line 56

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

#select(option) ⇒ Object



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

def select(option)
  option_node = node.find_element(:xpath, ".//option[text()='#{option}']") || node.find_element(:xpath, ".//option[contains(.,'#{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



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

def set(value)
  if tag_name == 'textarea' or (tag_name == 'input' and %w(text password hidden file).include?(type))
    node.clear
    node.send_keys(value.to_s)
  elsif tag_name == 'input' and type == 'radio'
    node.select
  elsif tag_name == 'input' and type == 'checkbox'
    node.toggle
  end
end

#tag_nameObject



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

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

#trigger(event) ⇒ Object



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

def trigger(event)
end

#unselect(option) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/capybara/driver/selenium_driver.rb', line 38

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[text()='#{option}']") || node.find_element(:xpath, ".//option[contains(.,'#{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

#visible?Boolean

Returns:

  • (Boolean)


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

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