Class: Watir::FileField

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

Constant Summary

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

#locate

Methods inherited from Element

#<=>, #__ole_inner_elements, #activeObjectHighLightColor, #assert_enabled, #assert_exists, #attribute_value, #click, #click!, #create_event, #disabled?, #dispatch_event, #document, #double_click, #enabled?, #exists?, #fire_event, #flash, #focus, #focused?, #initialize, #inspect, #locate, #method_missing, #ole_object, #ole_object=, #parent, #right_click, #send_keys, #style, #tag_name, #text, #to_s, #to_subtype, #type_keys, #typingspeed, #visible?

Methods included from DragAndDropHelper

#drag_and_drop_by, #drag_and_drop_on

Methods included from Container

#__ole_inner_elements, #alert, #locator_for, #modal_dialog, #set_container, support_element, #wait

Methods included from Exception

message_for_unable_to_locate

Methods included from ElementExtensions

#present?, #wait_until_present, #wait_while_present, #when_present

Constructor Details

This class inherits a constructor from Watir::Element

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:

  • (Errno::ENOENT)


14
15
16
# File 'lib/watir-classic/dialogs/file_field.rb', line 14

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

#cancel_buttonObject



26
27
28
# File 'lib/watir-classic/dialogs/file_field.rb', line 26

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

#file_upload_windowObject



30
31
32
# File 'lib/watir-classic/dialogs/file_field.rb', line 30

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

#open_buttonObject



22
23
24
# File 'lib/watir-classic/dialogs/file_field.rb', line 22

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

#set(file_path) ⇒ Object Also known as: value=



3
4
5
6
7
8
9
10
# File 'lib/watir-classic/dialogs/file_field.rb', line 3

def set(file_path)
  assert_file_exists(file_path)
  assert_exists
  click_no_wait
  set_file_name file_path.gsub(File::SEPARATOR, File::ALT_SEPARATOR)
  open_button.click
  Wait.until(5) {value.include?(File.basename(file_path))}
end

#set_file_name(path_to_file) ⇒ Object



18
19
20
# File 'lib/watir-classic/dialogs/file_field.rb', line 18

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