Class: Capybara::Selenium::Node
Instance Attribute Summary
Attributes inherited from Driver::Node
#driver, #native
Instance Method Summary
collapse
#initialize, #inspect, #path, #trigger
Instance Method Details
#==(other) ⇒ Object
79
80
81
|
# File 'lib/capybara/selenium/node.rb', line 79
def ==(other)
native == other.native
end
|
#[](name) ⇒ Object
7
8
9
10
11
|
# File 'lib/capybara/selenium/node.rb', line 7
def [](name)
native.attribute(name.to_s)
rescue Selenium::WebDriver::Error::WebDriverError
nil
end
|
#click ⇒ Object
51
52
53
|
# File 'lib/capybara/selenium/node.rb', line 51
def click
native.click
end
|
#drag_to(element) ⇒ Object
55
56
57
|
# File 'lib/capybara/selenium/node.rb', line 55
def drag_to(element)
driver.browser.action.drag_and_drop(native, element.native).perform
end
|
#find(locator) ⇒ Object
75
76
77
|
# File 'lib/capybara/selenium/node.rb', line 75
def find(locator)
native.find_elements(:xpath, locator).map { |n| self.class.new(driver, n) }
end
|
#select_option ⇒ Object
40
41
42
|
# File 'lib/capybara/selenium/node.rb', line 40
def select_option
native.click unless selected?
end
|
#selected? ⇒ Boolean
Also known as:
checked?
68
69
70
71
|
# File 'lib/capybara/selenium/node.rb', line 68
def selected?
selected = native.selected?
selected and selected != "false"
end
|
#set(value) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/capybara/selenium/node.rb', line 21
def set(value)
tag_name = self.tag_name
type = self[:type]
if (Array === value) && !self[:multiple]
raise ArgumentError.new "Value cannot be an Array when 'multiple' attribute is not present. Not a #{value.class}"
end
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 == 'input' and type == 'file'
path_names = value.to_s.empty? ? [] : value
native.send_keys(*path_names)
elsif tag_name == 'textarea' or tag_name == 'input'
driver.browser.execute_script "arguments[0].value = ''", native
native.send_keys(value.to_s)
end
end
|
#tag_name ⇒ Object
59
60
61
|
# File 'lib/capybara/selenium/node.rb', line 59
def tag_name
native.tag_name.downcase
end
|
#unselect_option ⇒ Object
44
45
46
47
48
49
|
# File 'lib/capybara/selenium/node.rb', line 44
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.click if selected?
end
|
#value ⇒ Object
13
14
15
16
17
18
19
|
# File 'lib/capybara/selenium/node.rb', line 13
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
63
64
65
66
|
# File 'lib/capybara/selenium/node.rb', line 63
def visible?
displayed = native.displayed?
displayed and displayed != "false"
end
|