Class: Capybara::Selenium::Node
Defined Under Namespace
Modules: Html5Drag
Instance Attribute Summary
Attributes inherited from Driver::Node
#driver, #initial_cache, #native
Instance Method Summary
collapse
Methods included from Scroll
#scroll_by, #scroll_to
Methods included from Find
#find_css, #find_xpath
#initialize, #inspect, #scroll_by, #scroll_to, #trigger
Instance Method Details
#==(other) ⇒ Object
159
160
161
|
# File 'lib/capybara/selenium/node.rb', line 159
def ==(other)
native == other.native
end
|
#[](name) ⇒ Object
25
26
27
28
29
|
# File 'lib/capybara/selenium/node.rb', line 25
def [](name)
native.attribute(name.to_s)
rescue Selenium::WebDriver::Error::WebDriverError
nil
end
|
#all_text ⇒ Object
16
17
18
19
20
21
22
23
|
# File 'lib/capybara/selenium/node.rb', line 16
def all_text
text = driver.evaluate_script('arguments[0].textContent', self)
text.gsub(/[\u200b\u200e\u200f]/, '')
.gsub(/[\ \n\f\t\v\u2028\u2029]+/, ' ')
.gsub(/\A[[:space:]&&[^\u00a0]]+/, '')
.gsub(/[[:space:]&&[^\u00a0]]+\z/, '')
.tr("\u00a0", ' ')
end
|
#click(keys = [], **options) ⇒ Object
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/capybara/selenium/node.rb', line 95
def click(keys = [], **options)
click_options = ClickOptions.new(keys, options)
return native.click if click_options.empty?
click_with_options(click_options)
rescue StandardError => e
if e.is_a?(::Selenium::WebDriver::Error::ElementClickInterceptedError) ||
e.message.match?(/Other element would receive the click/)
scroll_to_center
end
raise e
end
|
#content_editable? ⇒ Boolean
155
156
157
|
# File 'lib/capybara/selenium/node.rb', line 155
def content_editable?
native.attribute('isContentEditable')
end
|
#disabled? ⇒ Boolean
148
149
150
151
152
153
|
# File 'lib/capybara/selenium/node.rb', line 148
def disabled?
return true unless native.enabled?
find_xpath('self::fieldset/ancestor-or-self::fieldset[@disabled]').any?
end
|
#double_click(keys = [], **options) ⇒ Object
116
117
118
119
120
121
|
# File 'lib/capybara/selenium/node.rb', line 116
def double_click(keys = [], **options)
click_options = ClickOptions.new(keys, options)
click_with_options(click_options) do |action|
click_options.coords? ? action.double_click : action.double_click(native)
end
end
|
#drag_to(element) ⇒ Object
131
132
133
134
135
136
|
# File 'lib/capybara/selenium/node.rb', line 131
def drag_to(element)
scroll_if_needed { browser_action.click_and_hold(native).perform }
element.scroll_if_needed { browser_action.move_to(element.native).release.perform }
end
|
#hover ⇒ Object
127
128
129
|
# File 'lib/capybara/selenium/node.rb', line 127
def hover
scroll_if_needed { browser_action.move_to(native).perform }
end
|
#multiple? ⇒ Boolean
144
|
# File 'lib/capybara/selenium/node.rb', line 144
def multiple?; boolean_attr(self[:multiple]); end
|
#path ⇒ Object
163
164
165
|
# File 'lib/capybara/selenium/node.rb', line 163
def path
driver.evaluate_script GET_XPATH_SCRIPT, self
end
|
#readonly? ⇒ Boolean
143
|
# File 'lib/capybara/selenium/node.rb', line 143
def readonly?; boolean_attr(self[:readonly]); end
|
#right_click(keys = [], **options) ⇒ Object
109
110
111
112
113
114
|
# File 'lib/capybara/selenium/node.rb', line 109
def right_click(keys = [], **options)
click_options = ClickOptions.new(keys, options)
click_with_options(click_options) do |action|
click_options.coords? ? action.context_click : action.context_click(native)
end
end
|
#select_option ⇒ Object
85
86
87
|
# File 'lib/capybara/selenium/node.rb', line 85
def select_option
click unless selected? || disabled?
end
|
#selected? ⇒ Boolean
Also known as:
checked?
145
|
# File 'lib/capybara/selenium/node.rb', line 145
def selected?; boolean_attr(native.selected?); end
|
#send_keys(*args) ⇒ Object
123
124
125
|
# File 'lib/capybara/selenium/node.rb', line 123
def send_keys(*args)
native.send_keys(*args)
end
|
#set(value, **options) ⇒ Object
Set the value of the form element to the given value.
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/capybara/selenium/node.rb', line 56
def set(value, **options)
raise ArgumentError, "Value cannot be an Array when 'multiple' attribute is not present. Not a #{value.class}" if value.is_a?(Array) && !multiple?
tag_name, type = attrs(:tagName, :type)
case tag_name.downcase
when 'input'
case type.downcase
when 'radio'
click
when 'checkbox'
click if value ^ checked?
when 'file'
set_file(value)
when 'date'
set_date(value)
when 'time'
set_time(value)
when 'datetime-local'
set_datetime_local(value)
else
set_text(value, options)
end
when 'textarea'
set_text(value, options)
else
set_content_editable(value) if content_editable?
end
end
|
#style(styles) ⇒ Object
39
40
41
42
43
|
# File 'lib/capybara/selenium/node.rb', line 39
def style(styles)
styles.each_with_object({}) do |style, result|
result[style] = native.css_value(style)
end
end
|
#tag_name ⇒ Object
138
139
140
|
# File 'lib/capybara/selenium/node.rb', line 138
def tag_name
native.tag_name.downcase
end
|
#unselect_option ⇒ Object
89
90
91
92
93
|
# File 'lib/capybara/selenium/node.rb', line 89
def unselect_option
raise Capybara::UnselectNotAllowed, 'Cannot unselect option from single select box.' unless select_node.multiple?
click if selected?
end
|
#value ⇒ Object
31
32
33
34
35
36
37
|
# File 'lib/capybara/selenium/node.rb', line 31
def value
if tag_name == 'select' && multiple?
native.find_elements(:css, 'option:checked').map { |el| el[:value] || el.text }
else
native[:value]
end
end
|
#visible? ⇒ Boolean
142
|
# File 'lib/capybara/selenium/node.rb', line 142
def visible?; boolean_attr(native.displayed?); end
|
#visible_text ⇒ Object
12
13
14
|
# File 'lib/capybara/selenium/node.rb', line 12
def visible_text
native.text
end
|