Sha256: 78ae9a0e3a6ed1956afb2afc8edcc2a7bc4de6d82ea912597a64ec2d4d9a92bc

Contents?: true

Size: 1 KB

Versions: 10

Compression:

Stored size: 1 KB

Contents

# encoding: utf-8
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)
      assert_exists
      path = path.gsub(File::SEPARATOR, File::ALT_SEPARATOR) if File::ALT_SEPARATOR
      @element.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

10 entries across 10 versions & 1 rubygems

Version Path
watir-webdriver-0.6.11 lib/watir-webdriver/elements/file_field.rb
watir-webdriver-0.6.10 lib/watir-webdriver/elements/file_field.rb
watir-webdriver-0.6.9 lib/watir-webdriver/elements/file_field.rb
watir-webdriver-0.6.8 lib/watir-webdriver/elements/file_field.rb
watir-webdriver-0.6.7 lib/watir-webdriver/elements/file_field.rb
watir-webdriver-0.6.6 lib/watir-webdriver/elements/file_field.rb
watir-webdriver-0.6.5 lib/watir-webdriver/elements/file_field.rb
watir-webdriver-0.6.4 lib/watir-webdriver/elements/file_field.rb
watir-webdriver-0.6.3 lib/watir-webdriver/elements/file_field.rb
watir-webdriver-0.6.2 lib/watir-webdriver/elements/file_field.rb