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
A new instance of HTMLElements.
- #reset ⇒ Object
- #result ⇒ Object
- #start_element(name, attrs = []) ⇒ Object
Constructor Details
#initialize ⇒ HTMLElements
Returns a new instance of HTMLElements.
168 169 170 171 |
# File 'lib/appium_lib/common/helper.rb', line 168 def initialize reset @filter = false end |
Instance Attribute Details
#filter ⇒ Object
Returns the value of attribute filter.
159 160 161 |
# File 'lib/appium_lib/common/helper.rb', line 159 def filter @filter end |
Instance Method Details
#characters(chars) ⇒ Object
210 211 212 213 214 |
# File 'lib/appium_lib/common/helper.rb', line 210 def characters(chars) return if @skip_element element = @element_stack.last element[:text] = chars end |
#end_element(name) ⇒ Object
204 205 206 207 208 |
# File 'lib/appium_lib/common/helper.rb', line 204 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
173 174 175 176 177 |
# File 'lib/appium_lib/common/helper.rb', line 173 def reset @element_stack = [] @elements_in_order = [] @skip_element = false end |
#result ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/appium_lib/common/helper.rb', line 179 def result @elements_in_order.reduce('') do |r, e| name = e.delete :name attr_string = e.reduce('') do |string, attr| attr_1 = attr[1] attr_1 = attr_1 ? attr_1.strip : attr_1 string + " #{attr[0]}: #{attr_1}\n" end unless attr_string.nil? || attr_string.empty? r += "\n#{name}\n#{attr_string}" end r end end |
#start_element(name, attrs = []) ⇒ Object
195 196 197 198 199 200 201 202 |
# File 'lib/appium_lib/common/helper.rb', line 195 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 |