Sha256: a09ddac6a329447b2c184e74b2083f4acf5881397792161f5acc816aa17e67d7

Contents?: true

Size: 966 Bytes

Versions: 3

Compression:

Stored size: 966 Bytes

Contents

module Watir
  class FileField < Input

    #
    # Set the file field to the given path
    #
    # @param [String] a path
    # @raise [Errno::ENOENT] if the file doesn't exist
    #

    def set(path)
      raise Errno::ENOENT, path unless File.exist?(path)
      self.value = path
    end

    #
    # Sets the file field to the given path
    #
    # @param [String] path
    #

    def value=(path)
      path = path.gsub(File::SEPARATOR, File::ALT_SEPARATOR) if File::ALT_SEPARATOR
      send_keys path
    end

  end # FileField

  module Container
    def file_field(*args)
      FileField.new(self, extract_selector(args).merge(tag_name: "input", type: "file"))
    end

    def file_fields(*args)
      FileFieldCollection.new(self, extract_selector(args).merge(tag_name: "input", type: "file"))
    end
  end # Container

  class FileFieldCollection < InputCollection
    def element_class
      FileField
    end
  end # FileFieldCollection
end # Watir

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
watir-webdriver-0.9.1 lib/watir-webdriver/elements/file_field.rb
watir-webdriver-0.9.0 lib/watir-webdriver/elements/file_field.rb
watir-webdriver-0.8.0 lib/watir-webdriver/elements/file_field.rb