Sha256: 8de82dc74b8ce3cec875a7b1615e96907d3b87454801af90d36b3e8e36f3f80d

Contents?: true

Size: 1.13 KB

Versions: 30

Compression:

Stored size: 1.13 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 += %(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

30 entries across 30 versions & 1 rubygems

Version Path
appium_lib-9.4.7 lib/appium_lib/android/client_xpath.rb
appium_lib-9.4.6 lib/appium_lib/android/client_xpath.rb
appium_lib-9.4.5 lib/appium_lib/android/client_xpath.rb
appium_lib-9.4.4 lib/appium_lib/android/client_xpath.rb
appium_lib-9.4.3 lib/appium_lib/android/client_xpath.rb
appium_lib-9.4.2 lib/appium_lib/android/client_xpath.rb
appium_lib-9.4.1 lib/appium_lib/android/client_xpath.rb
appium_lib-9.4.0 lib/appium_lib/android/client_xpath.rb
appium_lib-9.3.8 lib/appium_lib/android/client_xpath.rb
appium_lib-9.3.7 lib/appium_lib/android/client_xpath.rb
appium_lib-9.3.6 lib/appium_lib/android/client_xpath.rb
appium_lib-9.3.5 lib/appium_lib/android/client_xpath.rb
appium_lib-9.3.4 lib/appium_lib/android/client_xpath.rb
appium_lib-9.3.3 lib/appium_lib/android/client_xpath.rb
appium_lib-9.3.2 lib/appium_lib/android/client_xpath.rb
appium_lib-9.3.1 lib/appium_lib/android/client_xpath.rb
appium_lib-9.3.0 lib/appium_lib/android/client_xpath.rb
appium_lib-9.2.0 lib/appium_lib/android/client_xpath.rb
appium_lib-9.1.3 lib/appium_lib/android/client_xpath.rb
appium_lib-9.1.2 lib/appium_lib/android/client_xpath.rb