I am writing a watir script to test an upload form.
But the script does not automatically choose the file that is to be uploaded from my harddrive.
Instead I
I had the same problem today (March1,2012) and landed here via Google.
Thanks Željko for pointing me in the right direction, however the solution of changing the [POPUP_TITLES] didn't work. In fact, this array seems not to exist anymore in the current version of the gem (watir-2.0.4), or maybe I just misread.
I solved the problem in watir-2.0.4/lib/watir/dialogs/file_field.rb
:
Here, the various window and button titles are defined as regular expressions. Change the regexps in the following methods
to match your localized window names. After reloading the gem, it worked flawlessly.
I installed windows xp in english now, and it works! (The error occured on a localised windows server 2003)
I guess it was the localisation issue. I will just run watir on the english computer from now on.
I knew about that problem, and completely forgot! Go to input_elements.rb file in your gems directory, and add the title of the file upload window in your language to POPUP_TITLES
(line 443).
Example:
before
POPUP_TITLES = ['Choose file', 'Choose File to Upload']
after
POPUP_TITLES = ['Choose file', 'Choose File to Upload', 'File upload in my language']
I would suggest that you take a look at FileField#set in input_elements.rb (in your Ruby gems directory), and change sleep 1
to sleep 2
(or some higher number). I have noticed that on slower machines it takes more than a second for file upload pop up to appear.
@modal = @browser.driver.switch_to.alert #Switch to open windows modal
key_to_send = "C:\\Users\\singhku\\Calabash_doc.pdf" #Path and name of file
@modal.send_keys(key_to_send)
require 'win32ole'
wsh = WIN32OLE.new('Wscript.Shell')
wsh.AppActivate('Choose File to Upload') #Name of the modal that is open
wsh.SendKeys('{ENTER}')