Class: Watir::FileField
- Inherits:
-
InputElement
- Object
- Element
- InputElement
- Watir::FileField
- Defined in:
- lib/watir/input_elements.rb
Overview
For fields that accept file uploads Windows dialog is opened and handled in this case by autoit launching into a new process. Normally a user would not need to create this object as it is returned by the Watir::Container#file_field method
Constant Summary collapse
- INPUT_TYPES =
:stopdoc:
["file"]
- POPUP_TITLES =
['Choose file', 'Choose File to Upload']
Constants inherited from Element
Instance Attribute Summary
Attributes inherited from Element
Attributes included from Container
#activeObjectHighLightColor, #page_container, #type_keys, #typingspeed
Instance Method Summary collapse
-
#set(path_to_file) ⇒ Object
set the file location in the Choose file dialog in a new process will raise a WatirException if AutoIt is not correctly installed.
Methods inherited from InputElement
Methods inherited from Element
#<=>, #activeObjectHighLightColor, #after_text, #assert_enabled, #assert_exists, #attribute_value, #before_text, #click, #click!, #document, #enabled?, #exists?, #fire_event, #flash, #focus, #initialize, #inspect, #method_missing, #ole_object, #ole_object=, #parent, #text, #to_s, #type_keys, #typingspeed, #visible?
Methods included from Container
#area, #areas, #button, #buttons, #cell, #cells, #checkbox, #checkboxes, #dds, #divs, #dls, #dts, #element, #element_by_css, #elements, #ems, #file_field, #file_fields, #form, #forms, #frame, #frames, #hidden, #hiddens, #image, #images, #labels, #link, #links, #lis, #locate_all_elements, #locate_input_element, #locate_tagged_element, #log, #map, #maps, #modal_dialog, #popup, #pres, #ps, #radio, #radios, #row, #rows, #select_list, #select_lists, #set_container, #show_all_objects, #spans, #strongs, #table, #tables, #text_field, #text_fields, #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
#set(path_to_file) ⇒ Object
set the file location in the Choose file dialog in a new process will raise a WatirException if AutoIt is not correctly installed
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 |
# File 'lib/watir/input_elements.rb', line 492 def set(path_to_file) assert_exists require 'watir/windowhelper' WindowHelper.check_autoit_installed begin Thread.new do sleep 1 # it takes some time for popup to appear system %{ruby -e ' require "win32ole" @autoit = WIN32OLE.new("AutoItX3.Control") time = Time.now while (Time.now - time) < 15 # the loop will wait up to 15 seconds for popup to appear #{POPUP_TITLES.inspect}.each do |popup_title| next unless @autoit.WinWait(popup_title, "", 1) == 1 @autoit.ControlSetText(popup_title, "", "Edit1", #{path_to_file.inspect}) @autoit.ControlSend(popup_title, "", "Button2", "{ENTER}") exit end # each end # while '} end.join(1) rescue raise Watir::Exception::WatirException, "Problem accessing Choose file dialog" end click end |