Sha256: a2f7d84e7c0abd4609e34563d93da3d4459c1887d791d9b3488080aff6ce17fd

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 KB

Contents

require 'nokogiri'

module Appium
  module Android
    def _nodeset_to_uiselector opts={}
      results = ''

      nodes = opts[:nodes]
      first = opts[:first]

      nodes = [nodes[0]] if first

      nodes.each do |node|
        results += %Q(new UiSelector().className("#{node.name}").instance(#{node.attr('instance')});)
      end

      results.strip
    end

    def _client_xpath opts={}
      root_node = Nokogiri::XML(get_source).children.first

      instance = Hash.new -1

      root_node.traverse do |node|
        number = instance[node.name] += 1
        node.set_attribute 'instance', number
      end

      nodes = root_node.xpath(opts[:xpath])
      first = opts[:first]

      _nodeset_to_uiselector nodes: nodes, first: first
    end

    def client_xpath xpath
      find_element :uiautomator, _client_xpath(xpath: xpath, first: true)
    end

    def client_xpaths xpath
      find_elements :uiautomator, _client_xpath(xpath: xpath, first: false)
    end
  end
end

# http://stackoverflow.com/questions/9199415/getting-first-node-in-xpath-result-set
# '(//android.widget.TextView)[1]' not '//android.widget.TextView[1]'

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
appium_lib-6.0.0 lib/appium_lib/android/client_xpath.rb
appium_lib-5.0.1 lib/appium_lib/android/client_xpath.rb
appium_lib-5.0.0 lib/appium_lib/android/client_xpath.rb
appium_lib-4.1.0 lib/appium_lib/android/client_xpath.rb