I encountered this problem yesterday, and unlike the mail archives, I have an answer. I was getting exactly the behavior described below: 1) I would run a script using file_field.set 2) The script would get to the set method 3a) the choose file window would be invoked 3b) the file setFileDialog.rb would be opened in my ruby editor 3c) the script would sit there waiting for me to take manual action. 4) As soon as I take manual action to close the window, the script would resume Messing around with autoit, and the other suggestions didn't help at all.
The problem seems to be caused by associating *.rb files with an IDE. When the set method attempts to start the thread that manipulates the Choose File window, the operating system directs the script to the IDE rather than to Ruby. As soon as I changed the association to the Ruby executable, the file_field set method worked happily. (Well, not quite happily... The method still doesn't like spaces in the path name, but that's an easy problem to solve.) I assume that Watir launching a new thread and telling the thread to execute setFileDialog.rb, while what it needs to do is tell the thread to execute setFileDialog.rb *with Ruby*. Either that or people getting this bug need to change the file associations. Michael Ruschena ________________________________ Cain, Mark Thu, 12 Jan 2006 07:32:28 -0800 What behavior do you see? When my script runs I see a Dos window open with focus (just like WinClicker), then the file chooser window open under the Dos window. The Dos window scrolls through all the objects open and finally gets to the File Chooser window, the document name (from $path) appears in the file name field, the open button is clicked and that information is transferred to the file_field text boxes. Finally the submit button is clicked and the file is attached. --Mark ________________________________ From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of chaya shetty Sent: Wednesday, January 11, 2006 10:11 PM To: [email protected] Subject: Re: [Wtr-general] How can I open and attach fileusingfile_fieldmethod? Hi, I tried as said...Even then I am facing the same problem. Code Used: $path = "C:/Watir/file.txt" $ie.file_field(:name,"srcfile").set($path) $autoit = WIN32OLE.new("AutoItX3.Control") $autoit.WinWait("Choose file", "Do you want to open or save this file?", 3) $autoit.WinActivate("Choose file") $autoit.WinWait("Choose file", "Look &in", 3) $autoit.ControlSetText("Choose file", "", "Edit1", "#{$path}") $autoit.ControlClick("Choose file", "Look &in", "&Open") $ie.button(:name, "Open").click The file field highlights(yellow)and opens choose file dialog along with another ruby file with contents: # # setFileDialog.rb # # # This file contains the file dialog when it runs as a separate process $LOAD_PATH <&! lt; File.expand_path(File.join(File.dirname(__FILE__), '..')) puts $LOAD_PATH require 'watir/winClicker' filepath = "invalid path passed to setFileDialog.rb" filepath = ARGV[0] unless ARGV[0] == nil clicker= WinClicker.new clicker.setFileRequesterFileName(filepath) clicker = nil Then it waits for me to manually select the file and attach. I have ensured that the path is correct and there is a text file viz. file in the Watir folder. Thanks, Chaya "Cain, Mark" <[EMAIL PROTECTED]> wrote: Replace all your $autoit lines with this: $autoit = WIN32OLE.new("AutoItX3.Control") $autoit.WinWait("Choose file", "Do you want to open or save this file?", 3) $autoit.WinActivate("Choose file") $autoit.WinWait("Choose file", "Look &in", 3) $autoit.ControlSetText("Choose file", "", "Edit1", "#{$path}") $autoit.ControlClick("Choose file", "Look &in", "&Open") I don't know if it will make a difference but my script needed the WinWait's left in to work right. Also, it took a little time for autoit to find the window so don't get impatient. Hope this helps, --Mark ________________________________ From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of chaya shetty Sent: Thursday, January 05, 2006 9:27 PM To: [email protected] Subject: Re: [Wtr-general] How can I open and attach file usingfile_fieldmethod? Hi, There is only one file field in the page and hence I tried with path = "C\:Watir\Text.doc" ie.file_field(:index,1).set(#{path}) $autoit = WIN32OLE.new("AutoItX3.Control") $autoit.WinActivate("Choose file") $autoit.ControlSetText("Choose file", "", "Edit1", "#{path}") $autoit.ControlClick("Choose file", "Look &in", "&Open") $ie.button(:name, "Submit").click B! ut still the same behaviour was seen. The file field was accessed and the "Choose File" window opened and waited till I manually selected the file. Thanks Chaya "Cain, Mark" <[EMAIL PROTECTED]> wrote: Yes, the problem is (:value, 'Value') in this line: ie.file_field(:value,'Value').set(#{path}) ! The file_field supports these attributes: :id, :name, :index. Do a view source and find out what the attribute values for your <input type = file> tag. If for some reason your developers were lazy and didn't give the tag an id or name attribute, use index. If there are more than one <input type = file> tag on the page the indexing starts top-most down with 1 and increments from there. Here is the usage portion for file_field from Watir.rb: # This is the main me! thod for accessing a file field. Usually an <input type = file> HTML tag. # * how - symbol - how we access the field , :index, :id, :name etc # * what - string, int or re , what we are looking for, # # returns a FileField object # # Typical Usage # # ie.file_field(:id, 'up_1') # access the file upload field with an ID of up_1 # ie.file_field(:name, 'upload') # access the file upload field with a name of upload # ie.file_field(:index, 2) # access the second file upload on the page ( 1 based, so the first field is accessed with :index,1) Hope this helps, --Mark ________________________________ From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of chaya shetty Sent: Thursday, January 05, 2006 4:45 AM To: [email protected] Subject: Re: [Wtr-general] How can I open and attach file using file_fieldmethod? Hi, I tried with path = "C\:Watir\Text.doc" ie.file_field(:value,'Value').set(#{path}) $autoit = WIN32OLE.new("AutoItX3.Control") $autoit.WinActivate("Choose file") $autoit.ControlSetText("Choose file", "", "Edit1", "#{path}") $autoit.ControlClick("Choose file", "Look &in", "&Open") $ie.button(:name, "Submit").click But the same behaviour persists. i.e. the "Choose File" window opens and waits till you manually select the file. Can't ie.file_field(:value,'Value').set(#{path}) automatically set the path? Thanks Chaya --Mark Amitha Shetty <[EMAIL PROTECTED]> wrote: Hi, How can I open and attach file using file_field method? when I try, ie.file_field(:id,'uploaded_file').set('C:\file.txt') I get "choose file"-window open .It waits for me, to choose a file and click "open" or whatever the button is called) , after that it continues normally, by submitting the file_field content. Why doesn't he choose a file by himself?How do I handle this? I have ensured that there is no space in the path and the file exists in C: ) I get the same error when I run filefield_test in Unittests in watir folder. Thanks, Amitha Send instant messages to your online friends http://in.messenger.yahoo.com _______________________________________________ Wtr-general mailing list [email protected] http://rubyforge.org/mailman/listinfo/wtr-general Send instant messages to your online friends http://in.messenger.yahoo.com _______________________________________________ Wtr-general mailing list [email protected] http://rubyforge.org/mailman/listinfo/wtr-general Send instant messages to your online friends http://in.messenger.yahoo.com _______________________________________________ Wtr-general mailing list [email protected] http://rubyforge.org/mailman/listinfo/wtr-general _______________________________________________ Wtr-general mailing list [email protected] http://rubyforge.org/mailman/listinfo/wtr-general
