Class: Watir::FileField

Inherits:
InputElement show all
Defined in:
lib/watir/dialogs/file_field.rb

Constant Summary collapse

INPUT_TYPES =

:stopdoc:

["file"]

Constants inherited from Element

Element::TO_S_SIZE

Instance Attribute Summary

Attributes inherited from Element

#container

Attributes included from Container

#activeObjectHighLightColor, #page_container, #type_keys, #typingspeed

Instance Method Summary collapse

Methods inherited from InputElement

#initialize, #locate

Methods inherited from Element

#<=>, #__ole_inner_elements, #activeObjectHighLightColor, #after_text, #assert_enabled, #assert_exists, #attribute_value, #before_text, #click, #click!, #create_event, #dispatch_event, #document, #enabled?, #exists?, #fire_event, #flash, #focus, inherited, #initialize, #inspect, #locate, #method_missing, #name, #ole_object, #ole_object=, #parent, #text, #to_s, #type_keys, #typingspeed, #visible?

Methods included from Container

#__ole_inner_elements, #input_element_locator, #locator_for, #log, #set_container, #show_all_objects, #tagged_element_locator, #wait

Constructor Details

This class inherits a constructor from Watir::InputElement

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Watir::Element

Instance Method Details

#assert_file_exists(file_path) ⇒ Object

Raises:

  • (WatirException)


15
16
17
# File 'lib/watir/dialogs/file_field.rb', line 15

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

#cancel_buttonObject



27
28
29
# File 'lib/watir/dialogs/file_field.rb', line 27

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

#file_upload_windowObject



31
32
33
# File 'lib/watir/dialogs/file_field.rb', line 31

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

#open_buttonObject



23
24
25
# File 'lib/watir/dialogs/file_field.rb', line 23

def open_button
  file_upload_window.button(:value => '&Open')
end

#set(file_path) ⇒ Object

:startdoc:



7
8
9
10
11
12
13
# File 'lib/watir/dialogs/file_field.rb', line 7

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

#set_file_name(path_to_file) ⇒ Object



19
20
21
# File 'lib/watir/dialogs/file_field.rb', line 19

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