Re: [Wtr-general] How can I open and attach file using file_field method?
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: wtr-general@rubyforge.org 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: wtr-general@rubyforge.org 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
Re: [Wtr-general] How can I open and attach file using file_field method?
If you want it fixed, enter a new case at Jira (http://jira.openqa.org/browse/WTR), so it would not be forgotten. ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] How can I open and attach file using file_field method?
Thanks for solving this problem.Now that we have a click_no_wait method, we shouldn't have to resort to external *.rb files in the first place.BretOn 6/1/06, Michael Ruschena [EMAIL PROTECTED] wrote: I encountered this problem yesterday, and unlike the mail archives, I havean answer. I was getting exactly the behavior described below:1) I would run a script using file_field.set2) The script would get to the set method 3a) the choose file window would be invoked3b) the file setFileDialog.rb would be opened in my ruby editor3c) 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 resumeMessing 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. Whenthe set method attempts to start the thread that manipulates the Choose File window, the operating system directs the script to the IDE rather than toRuby. As soon as I changed the association to the Ruby executable, thefile_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 tosolve.)I assume that Watir launching a new thread and telling the thread to executesetFileDialog.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 tochange the file associations.Michael RuschenaCain, MarkThu, 12 Jan 2006 07:32:28 -0800 What behavior do you see?When my script runs I see a Dos window open withfocus (just like WinClicker), then the file chooser window open under theDos window.The Dos window scrolls through all the objects open and finally gets to the File Chooser window, the document name (from $path) appears inthe file name field, the open button is clicked and that information istransferred to the file_field text boxes.Finally the submit button is clicked and the file is attached.--MarkFrom: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of chaya shettySent: Wednesday, January 11, 2006 10:11 PM To: wtr-general@rubyforge.orgSubject: Re: [Wtr-general] How can I open and attachfileusingfile_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).clickThe 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_PATHrequire 'watir/winClicker'filepath = invalid path passed to setFileDialog.rbfilepath = ARGV[0] unless ARGV[0] == nilclicker= WinClicker.newclicker.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. filein the Watir folder. Thanks,ChayaCain, 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 thisfile?, 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 theWinWait's left in to work right.Also, it took a little time for autoit tofind the window so don't get impatient. Hope this helps,--MarkFrom: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On BehalfOf chaya shettySent: Thursday, January 05, 2006 9:27 PM To: wtr-general@rubyforge.orgSubject: Re: [Wtr-general] How can I open and attach fileusingfile_fieldmethod?Hi,There is only one file field in the page and hence I tried with path = C\:Watir\Text.docie.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).clickB! 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.ThanksChayaCain, 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
Re: [Wtr-general] How can I open and attach file using file_field method?
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: wtr-general@rubyforge.org 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 fieldhighlights(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 itwaits for me to manually select the file and attach. I have ensured that the path is correct and there is atext 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 dont know if it will make a difference but my script needed the WinWaits left in to work right. Also, it took a little time for autoit to find the window so dont 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: wtr-general@rubyforge.org Subject: Re: [Wtr-general] How can I open and attach file usingfile_fieldmethod? Hi, There is only one file field in the page and henceI 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 didnt 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]
Re: [Wtr-general] How can I open and attach file using file_field method?
Hi, 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 When I run this codethe file fieldhighlights(yellow) andthe 'Choose File' dialog opens. But the path is not set in the 'Choose File ' dialog. Along with this there is another file ' setFileDialog.rb ' that opens automatically.The contents of ' setFileDialog.rb ' are as follows: ### 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_PATHrequire 'watir/winClicker'filepath = "invalid path passed to setFileDialog.rb"filepath = ARGV[0] unless ARGV[0]! == nilclicker= WinClicker.newclicker.setFileRequesterFileName(filepath)clicker = nilThanks ChayaSend instant messages to your online friends http://in.messenger.yahoo.com ___Wtr-general mailing listWtr-general@rubyforge.orghttp://rubyforge.org/mailman/listinfo/wtr-general Send instant messages to your online friends http://in.messenger.yahoo.com ___Wtr-general mailing listWtr-general@rubyforge.orghttp://rubyforge.org/mailman/listinfo/wtr-general Send instant messages to your online friends http://in.messenger.yahoo.com ___Wtr-general maili! ng listWtr-general@rubyforge.orghttp://rubyforge.org/mailman/listinfo/wtr-general Send instant messages to your online friends http://in.messenger.yahoo.com ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general