Class: Capybara::Driver::RackTest::Node
- Inherits:
-
Node
- Object
- Node
- Capybara::Driver::RackTest::Node
show all
- Defined in:
- lib/capybara/driver/rack_test_driver.rb
Direct Known Subclasses
Form
Instance Attribute Summary
Attributes inherited from Node
#driver, #native
Instance Method Summary
collapse
Methods inherited from Node
#drag_to, #initialize, #inspect, #trigger
Instance Method Details
#[](name) ⇒ Object
13
14
15
|
# File 'lib/capybara/driver/rack_test_driver.rb', line 13
def [](name)
string_node[name]
end
|
#checked? ⇒ Boolean
71
72
73
|
# File 'lib/capybara/driver/rack_test_driver.rb', line 71
def checked?
self[:checked]
end
|
#click ⇒ Object
53
54
55
56
57
58
59
60
61
|
# File 'lib/capybara/driver/rack_test_driver.rb', line 53
def click
if tag_name == 'a'
method = self["data-method"] || :get
driver.process(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")
Form.new(driver, form).submit(self)
end
end
|
#find(locator) ⇒ Object
83
84
85
|
# File 'lib/capybara/driver/rack_test_driver.rb', line 83
def find(locator)
native.xpath(locator).map { |n| self.class.new(driver, n) }
end
|
#path ⇒ Object
79
80
81
|
# File 'lib/capybara/driver/rack_test_driver.rb', line 79
def path
native.path
end
|
#select_option ⇒ Object
39
40
41
42
43
44
|
# File 'lib/capybara/driver/rack_test_driver.rb', line 39
def select_option
if select_node['multiple'] != 'multiple'
select_node.find(".//option[@selected]").each { |node| node.native.remove_attribute("selected") }
end
native["selected"] = 'selected'
end
|
#selected? ⇒ Boolean
75
76
77
|
# File 'lib/capybara/driver/rack_test_driver.rb', line 75
def selected?
self[:selected]
end
|
#set(value) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/capybara/driver/rack_test_driver.rb', line 21
def set(value)
if tag_name == 'input' and type == 'radio'
other_radios_xpath = XPath.generate { |x| x.anywhere(:input)[x.attr(:name).equals(self[:name])] }.to_s
driver.html.xpath(other_radios_xpath).each { |node| node.remove_attribute("checked") }
native['checked'] = 'checked'
elsif tag_name == 'input' and type == 'checkbox'
if value && !native['checked']
native['checked'] = 'checked'
elsif !value && native['checked']
native.remove_attribute('checked')
end
elsif tag_name == 'input'
native['value'] = value.to_s
elsif tag_name == "textarea"
native.content = value.to_s
end
end
|
#tag_name ⇒ Object
63
64
65
|
# File 'lib/capybara/driver/rack_test_driver.rb', line 63
def tag_name
native.node_name
end
|
#text ⇒ Object
9
10
11
|
# File 'lib/capybara/driver/rack_test_driver.rb', line 9
def text
native.text
end
|
#unselect_option ⇒ Object
46
47
48
49
50
51
|
# File 'lib/capybara/driver/rack_test_driver.rb', line 46
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
17
18
19
|
# File 'lib/capybara/driver/rack_test_driver.rb', line 17
def value
string_node.value
end
|
#visible? ⇒ Boolean
67
68
69
|
# File 'lib/capybara/driver/rack_test_driver.rb', line 67
def visible?
string_node.visible?
end
|