Class: Appium::Common::HTMLElements
- Inherits:
-
Nokogiri::XML::SAX::Document
- Object
- Nokogiri::XML::SAX::Document
- Appium::Common::HTMLElements
- Defined in:
- lib/appium_lib/common/helper.rb
Instance Attribute Summary collapse
-
#filter ⇒ Object
Returns the value of attribute filter.
Instance Method Summary collapse
- #characters(chars) ⇒ Object
- #end_element(name) ⇒ Object
-
#initialize ⇒ HTMLElements
constructor
rubocop:disable Lint/MissingSuper.
- #reset ⇒ Object
- #result ⇒ Object
- #start_element(name, attrs = []) ⇒ Object
Constructor Details
#initialize ⇒ HTMLElements
rubocop:disable Lint/MissingSuper
217 218 219 220 |
# File 'lib/appium_lib/common/helper.rb', line 217 def initialize # rubocop:disable Lint/MissingSuper reset @filter = false end |
Instance Attribute Details
#filter ⇒ Object
Returns the value of attribute filter.
207 208 209 |
# File 'lib/appium_lib/common/helper.rb', line 207 def filter @filter end |
Instance Method Details
#characters(chars) ⇒ Object
259 260 261 262 263 264 |
# File 'lib/appium_lib/common/helper.rb', line 259 def characters(chars) return if @skip_element element = @element_stack.last element[:text] = chars end |
#end_element(name) ⇒ Object
252 253 254 255 256 257 |
# File 'lib/appium_lib/common/helper.rb', line 252 def end_element(name) return if filter && !filter.include?(name.downcase) element_index = @element_stack.rindex { |e| e[:name] == name } @element_stack.delete_at element_index end |
#reset ⇒ Object
222 223 224 225 226 |
# File 'lib/appium_lib/common/helper.rb', line 222 def reset @element_stack = [] @elements_in_order = [] @skip_element = false end |
#result ⇒ Object
228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/appium_lib/common/helper.rb', line 228 def result @elements_in_order.reduce('') do |r, e| name = e.delete :name attr_string = e.reduce('') do |string, attr| attr1 = attr[1] ? attr[1].strip : attr[1] "#{string} #{attr[0]}: #{attr1}\n" end return r if attr_string.nil? || attr_string.empty? "#{r}\n#{name}\n#{attr_string}" end end |
#start_element(name, attrs = []) ⇒ Object
242 243 244 245 246 247 248 249 250 |
# File 'lib/appium_lib/common/helper.rb', line 242 def start_element(name, attrs = []) @skip_element = filter && !filter.include?(name.downcase) return if @skip_element element = { name: name } attrs.each { |a| element[a[0]] = a[1] } @element_stack.push element @elements_in_order.push element end |