Class: Watir::FileField

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

Overview

Returned by Container#file_field.

Constant Summary collapse

WINDOW_TITLES =

File upload dialog titles to search for.

Examples:

When the title of your IE dialog is missing, add a new one:

Watir::FileField::WINDOW_TITLES << "My missing title"    
[/choose file( to upload)?/i, "Elegir archivos para cargar", "Datei zum Hochladen"]
OK_BUTTON_VALUES =

File upload dialog “OK” button values to search for.

Examples:

When the “OK” button of your IE is missing, add a new one:

Watir::FileField::OK_BUTTON_VALUES << "My missing button value"    
['&Open', '&Abrir', '&ffnen']
CANCEL_BUTTON_VALUES =

File upload dialog “Cancel” button values to search for.

Examples:

When the “Cancel” button of your IE is missing, add a new one:

Watir::FileField::CANCEL_BUTTON_VALUES << "My missing button value"    
['Cancel', 'Abbrechen']

Instance Attribute Summary

Attributes inherited from Element

#container

Attributes included from Container

#page_container

Instance Method Summary collapse

Methods inherited from InputElement

#alt, #disabled?, #label, #name, #required?, #src, #type, #value

Methods inherited from Element

#<=>, #attribute_value, #class_name, #click, #disabled?, #double_click, #enabled?, #exists?, #fire_event, #flash, #focus, #focused?, #id, #initialize, #inner_html, #inspect, #method_missing, #ole_object, #outer_html, #parent, #right_click, #send_keys, #style, #tag_name, #text, #title, #to_s, #to_subtype, #unique_number, #visible?

Methods included from DragAndDropHelper

#drag_and_drop_by, #drag_and_drop_on

Methods included from Container

#a, #abbr, #address, #alert, #area, #article, #aside, #audio, #b, #base, #bdi, #bdo, #blockquote, #body, #br, #button, #canvas, #caption, #checkbox, #cite, #code, #col, #colgroup, #command, #data, #datalist, #dd, #del, #details, #dfn, #div, #dl, #dt, #element, #em, #embed, #fieldset, #figcaption, #figure, #file_field, #font, #footer, #form, #frame, #frameset, #h1, #h2, #h3, #h4, #h5, #h6, #head, #header, #hgroup, #hidden, #hr, #i, #img, #input, #ins, #kbd, #keygen, #label, #legend, #li, #map, #mark, #menu, #meta, #meter, #modal_dialog, #nav, #noscript, #object, #ol, #optgroup, #option, #output, #p, #param, #pre, #progress, #q, #radio, #rp, #rt, #ruby, #s, #samp, #script, #section, #select, #small, #source, #span, #strong, #style, #sub, #summary, #sup, #table, #tbody, #td, #text_field, #textarea, #tfoot, #th, #thead, #time, #title, #tr, #track, #u, #ul, #var, #video, #wbr

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

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

Set the path of the file field.

Examples:

browser.file_field.set("c:/foo/bar.txt")

Parameters:

  • file_path (String)

    absolute path to existing file.

Raises:

  • (Errno::ENOENT)

    when file does not exist.



30
31
32
33
34
35
36
37
# File 'lib/watir-classic/dialogs/file_field.rb', line 30

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