Sha256: 5a4de4f3ee6cc7be7f31f8a7a029ebbe2bc39afc1fcdc9eacca91eb545902226

Contents?: true

Size: 1 KB

Versions: 5

Compression:

Stored size: 1 KB

Contents

# encoding: utf-8
module Watir
  module Container
    include XpathSupport

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

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

    private

    ATOMS = {
      :fireEvent    => File.read(File.expand_path("../atoms/fireEvent.js", __FILE__)),
      :getOuterHtml => File.read(File.expand_path("../atoms/getOuterHtml.js", __FILE__))
    }

    def execute_atom(function_name, *arguments)
      script = "return (%s).apply(null, arguments)" % ATOMS.fetch(function_name)
      driver.execute_script(script, *arguments)
    end

    def extract_selector(selectors)
      case selectors.size
      when 2
        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 or (:how, 'what'), got #{selectors.inspect}"
    end

  end # Container
end # Watir

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
watir-webdriver-0.2.8 lib/watir-webdriver/container.rb
watir-webdriver-0.2.7 lib/watir-webdriver/container.rb
watir-webdriver-0.2.6 lib/watir-webdriver/container.rb
watir-webdriver-0.2.5 lib/watir-webdriver/container.rb
watir-webdriver-0.2.4 lib/watir-webdriver/container.rb