Class: Capybara::RackTest::Node
Direct Known Subclasses
Form
Instance Attribute Summary
Attributes inherited from Driver::Node
#driver, #native
Instance Method Summary
collapse
#drag_to, #hover, #initialize, #inspect, #trigger
Instance Method Details
#==(other) ⇒ Object
95
96
97
|
# File 'lib/capybara/rack_test/node.rb', line 95
def ==(other)
native == other.native
end
|
#[](name) ⇒ Object
10
11
12
|
# File 'lib/capybara/rack_test/node.rb', line 10
def [](name)
string_node[name]
end
|
#checked? ⇒ Boolean
67
68
69
|
# File 'lib/capybara/rack_test/node.rb', line 67
def checked?
string_node.checked?
end
|
#click ⇒ Object
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/capybara/rack_test/node.rb', line 48
def click
if tag_name == 'a'
method = self["data-method"] if driver.options[:respect_data_method]
method ||= :get
driver.follow(method, self[:href].to_s)
elsif (tag_name == 'input' and %w(submit image).include?(type)) or
((tag_name == 'button') and type.nil? or type == "submit")
Capybara::RackTest::Form.new(driver, form).submit(self)
end
end
|
#disabled? ⇒ Boolean
75
76
77
78
79
80
81
|
# File 'lib/capybara/rack_test/node.rb', line 75
def disabled?
if %w(option optgroup).include? tag_name
string_node.disabled? || find_xpath("parent::*")[0].disabled?
else
string_node.disabled?
end
end
|
#find_css(locator) ⇒ Object
91
92
93
|
# File 'lib/capybara/rack_test/node.rb', line 91
def find_css(locator)
native.css(locator, Capybara::RackTest::CSSHandlers.new).map { |n| self.class.new(driver, n) }
end
|
#find_xpath(locator) ⇒ Object
87
88
89
|
# File 'lib/capybara/rack_test/node.rb', line 87
def find_xpath(locator)
native.xpath(locator).map { |n| self.class.new(driver, n) }
end
|
#path ⇒ Object
83
84
85
|
# File 'lib/capybara/rack_test/node.rb', line 83
def path
native.path
end
|
#select_option ⇒ Object
34
35
36
37
38
39
|
# File 'lib/capybara/rack_test/node.rb', line 34
def select_option
if select_node['multiple'] != 'multiple'
select_node.find_xpath(".//option[@selected]").each { |node| node.native.remove_attribute("selected") }
end
native["selected"] = 'selected'
end
|
#selected? ⇒ Boolean
71
72
73
|
# File 'lib/capybara/rack_test/node.rb', line 71
def selected?
string_node.selected?
end
|
#set(value) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/capybara/rack_test/node.rb', line 18
def set(value)
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 radio?
set_radio(value)
elsif checkbox?
set_checkbox(value)
elsif input_field?
set_input(value)
elsif textarea?
native.content = value.to_s unless self[:readonly]
end
end
|
#tag_name ⇒ Object
59
60
61
|
# File 'lib/capybara/rack_test/node.rb', line 59
def tag_name
native.node_name
end
|
#unselect_option ⇒ Object
41
42
43
44
45
46
|
# File 'lib/capybara/rack_test/node.rb', line 41
def unselect_option
if select_node['multiple'] != 'multiple'
raise Capybara::UnselectNotAllowed, "Cannot unselect option from single select box."
end
native.remove_attribute('selected')
end
|
#value ⇒ Object
14
15
16
|
# File 'lib/capybara/rack_test/node.rb', line 14
def value
string_node.value
end
|
#visible? ⇒ Boolean
63
64
65
|
# File 'lib/capybara/rack_test/node.rb', line 63
def visible?
string_node.visible?
end
|