Sha256: 3815026d780c69761fef53bd8ec0db550cfd7838b81c8ecd5b55852b7aa81b36

Contents?: true

Size: 901 Bytes

Versions: 2

Compression:

Stored size: 901 Bytes

Contents

module Watir
  class FileField < InputElement
    #:stopdoc:
    INPUT_TYPES = ["file"]
    #:startdoc:

    def set(file_path)
      assert_file_exists(file_path)
      assert_exists
      click_no_wait
      set_file_name file_path
      open_button.click
    end

    def assert_file_exists(file_path)
      raise WatirException, "#{file_path} has to exist to set!" unless File.exists?(file_path)
    end

    def set_file_name(path_to_file)
      file_upload_window.text_field(:class => 'Edit', :index => 0).set path_to_file
    end

    def open_button
      file_upload_window.button(:value => /&Open|&Abrir/)
    end

    def cancel_button
      file_upload_window.button(:value => /Cancel/)
    end

    def file_upload_window
      @window ||= RAutomation::Window.new(:title => /^choose file( to upload)?|Elegir archivos para cargar$/i)
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
watir-2.0.4 lib/watir/dialogs/file_field.rb
watir-2.0.3 lib/watir/dialogs/file_field.rb