Sha256: 8cda589c6a47395ec5d8918b7e2ec07858c3126531a1018efec6584ffea11f09

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 KB

Contents

module Watir
  module Container
    include XpathSupport
    include JSSnippets

    #
    # Returns element.
    #
    # @example
    #   browser.element(data_bind: 'func')
    #
    # @return [HTMLElement]
    #

    def element(*args)
      HTMLElement.new(self, extract_selector(args))
    end

    #
    # Returns element collection.
    #
    # @example
    #   browser.elements(data_bind: 'func')
    #
    # @return [HTMLElementCollection]
    #

    def elements(*args)
      HTMLElementCollection.new(self, extract_selector(args))
    end

    #
    # @api private
    #

    def extract_selector(selectors)
      case selectors.size
      when 2
        Watir.logger.deprecate "Using ordered parameters to locate elements (:#{selectors.first}, #{selectors.last.inspect})",
                               "{#{selectors.first}: #{selectors.last.inspect}}",
                               ids: [:selector_parameters]
        return { selectors[0] => selectors[1] }
      when 1
        obj = selectors.first
        return obj if obj.kind_of? Hash
      when 0
        return {}
      end

      raise ArgumentError, "expected Hash, got #{selectors.inspect}"
    end

  end # Container
end # Watir

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
watir-6.13.0 lib/watir/container.rb
watir-6.12.0 lib/watir/container.rb