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

Instance Method Summary collapse

Methods inherited from Node

#initialize, #inspect, #path, #trigger

Constructor Details

This class inherits a constructor from Capybara::Driver::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
    value
  else
    native.attribute(name.to_s)
  end
rescue Selenium::WebDriver::Error::WebDriverError
  nil
end

#clickObject



49
50
51
# File 'lib/capybara/driver/selenium_driver.rb', line 49

def click
  native.click
end

#drag_to(element) ⇒ Object



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

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

#find(locator) ⇒ Object



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

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

#select_optionObject



38
39
40
# File 'lib/capybara/driver/selenium_driver.rb', line 38

def select_option
  native.select
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'
    native.click
  elsif tag_name == 'input' and type == 'checkbox'
    native.click if value ^ native.attribute('checked').to_s.eql?("true")
  elsif tag_name == 'textarea' or tag_name == 'input'
    native.clear
    native.send_keys(value.to_s)
  end
end

#tag_nameObject



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

def tag_name
  native.tag_name
end

#textObject



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

def text
  native.text
end

#unselect_optionObject



42
43
44
45
46
47
# File 'lib/capybara/driver/selenium_driver.rb', line 42

def unselect_option
  if select_node['multiple'] != 'multiple' and select_node['multiple'] != 'true'
    raise Capybara::UnselectNotAllowed, "Cannot unselect option from single select box."
  end
  native.clear
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] 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)


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

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