Handling a windows file upload dialog box

1,824 views
Skip to first unread message

Rats

unread,
Apr 6, 2010, 12:07:19 AM4/6/10
to Watir General
Firstly, I should have probably mentioned in my previous posts I am a
Watir newbie. However I have done a fair bit or programming so have
some knowledge when it comes to using Watir.

Ok, my latest problem is to do with handling a windows file upload
dialog box. I've done searches through this NG and found that this is
a fairly common problem. The solutions I've come across suggest use
of .click_no_wait.

I'm trying to write some code that will click the file upload button,
enter a file name (full path) in the file name field and then hit
enter. This is what I tried:

ie.button(:name, "file_upload_button").click_no_wait
ie.send_keys("c:\test.txt")
ie.send_keys("{ENTER}")

Unfortunately click_no_wait just flashes the button and the dialog box
does not pop up. I've tried click by itself and that opens the dialog
box but of course the rest of the script does not execute.

Any ideas?

Wesley Chen

unread,
Apr 6, 2010, 3:26:41 AM4/6/10
to watir-...@googlegroups.com
For file upload button, there is a ready method, named:
$ie.file_field(:name, "").set("your file.txt")

Wesley.
For life, the easier, the better.



--
Before posting, please read http://watir.com/support. In short: search before you ask, be nice.

You received this message because you are subscribed to http://groups.google.com/group/watir-general
To post: watir-...@googlegroups.com

To unsubscribe, reply using "remove me" as the subject.

Željko Filipin

unread,
Apr 6, 2010, 6:07:55 AM4/6/10
to watir-...@googlegroups.com
On Tue, Apr 6, 2010 at 9:26 AM, Wesley Chen <cjq...@gmail.com> wrote:
> $ie.file_field(:name, "").set("your file.txt")

And we have a wiki page:

http://wiki.openqa.org/display/WTR/File+Uploads

Željko
--
watir.com - community manager
pledgie.com/campaigns/2982 - donate to Watir
watirpodcast.com - host
testingpodcast.com - audio podcasts on software testing. all of them

Message has been deleted

mani racha

unread,
Aug 2, 2012, 9:41:35 AM8/2/12
to watir-...@googlegroups.com, crapa...@yahoo.com.au

Hi all,
I'm trying to upload a file in a webpage with watir.
After so much of work,I've founded the link http://wiki.openqa.org/display/WTR/File+Uploads .
but it didn't work for me.

ie.button(:name, "file_upload_button").click_no_wait
ie.send_keys("c:\test.txt")
ie.send_keys("{ENTER}") 


$ie.file_field(:name, "").set("your file.txt")

I've tried with above 2 suggested snippets.(What is the file_field exactly???)
But neither of them given result.
Any one help me out plzz??
 

Dan

unread,
Aug 2, 2012, 9:46:22 AM8/2/12
to watir-...@googlegroups.com, crapa...@yahoo.com.au
You'll want to be looking for an element like this:

<input type="file" name="fileUpload">

Then you would do something like this:
$ie.file_field(:name, "fileUpload").set("your file.txt")

mani racha

unread,
Aug 3, 2012, 2:24:45 AM8/3/12
to watir-...@googlegroups.com, crapa...@yahoo.com.au

Hi Dan,

Thanks for your quick reply.
I have tried with your suggestion.

But it says
       `set': No such file or directory - hi.txt
Although the file is present. 

Is there any other ways to crack this??
 

Eric Mathiesen

unread,
Aug 3, 2012, 2:26:39 AM8/3/12
to watir-...@googlegroups.com

Try absolute pathing...  see if that works.

> --
> Before posting, please read http://watir.com/support. In short: search before you ask, be nice.
>  

> watir-...@googlegroups.com
> http://groups.google.com/group/watir-general
> watir-genera...@googlegroups.com
;t

mani racha

unread,
Aug 3, 2012, 2:44:29 AM8/3/12
to watir-...@googlegroups.com, crapa...@yahoo.com.au

Hi Eric,

've tried with your suggestion.
oops......Its also of no use. 

Super Kevy

unread,
Aug 3, 2012, 9:27:32 AM8/3/12
to watir-...@googlegroups.com
Check http://www.w3schools.com/jsref/dom_obj_fileupload.asp about the object your likely to be working with if standard html and not a flash based object.
 
You will find the form syntax something like: <input type="file" ....  >.  Get it? "type=file"
 
Basic HTML is nice to know w3Schools offers easy to learn tutorials.

mani racha

unread,
Aug 3, 2012, 9:32:49 AM8/3/12
to watir-...@googlegroups.com
Hi kevy,
that's so nice of you although it doesn't give me the result.


--

Dan

unread,
Aug 3, 2012, 9:37:07 AM8/3/12
to watir-...@googlegroups.com
If you're getting :

`set': No such file or directory - hi.txt

Then your path to the file isn't right.

b.file_input(:id => "fileuploadbox").set("C:\\folder\\hi.text")

or

b.file_input(:id => "fileuploadbox").set("C:/folder/hi.text")

or on a mac/linux

b.file_input(:id => "fileuploadbox").set("/Users/mani/Desktop/hi.text")

mani racha

unread,
Aug 4, 2012, 2:13:53 AM8/4/12
to watir-...@googlegroups.com
Hi Dan,
  Thank you for your lines of code.
  Unfortunately neither of them worked.


mani racha

unread,
Aug 4, 2012, 7:52:03 AM8/4/12
to watir-...@googlegroups.com
What is the problem with "set" method ?

Jarmo Pertman

unread,
Aug 4, 2012, 8:31:34 AM8/4/12
to watir-...@googlegroups.com
"not worked" is not enough descriptive for anyone to actually help you. Try to be more concise.

What does this line output to you:
puts browser.file_field(:name => "name_of_your_file_field").html

Jarmo Pertman
-----
IT does really matter - http://itreallymatters.net

mani racha

unread,
Aug 4, 2012, 8:35:50 AM8/4/12
to watir-...@googlegroups.com
Hi,
I have wrote

sFileName= "C:\\Users\\manikanth\\Desktop\\hi.docx"
browser.file_field(:name,'userfile').set(sFileName)

and it says,
C:/Ruby187/lib/ruby/gems/1.8/gems/watir-webdriver-0.6.1/lib/watir-webdriver/elem
ents/file_field.rb:13:in `set': No such file or directory - C:UsersmanikanthDesk
tophai.txt (Errno::ENOENT)

Željko Filipin

unread,
Aug 4, 2012, 8:52:52 AM8/4/12
to watir-...@googlegroups.com
On Sat, Aug 4, 2012 at 2:35 PM, mani racha <mani...@gmail.com> wrote:
> C:/Ruby187/lib/ruby/gems/1.8/gems/watir-webdriver-0.6.1/lib/watir-webdriver/elem
> ents/file_field.rb:13:in `set': No such file or directory - C:UsersmanikanthDesk
> tophai.txt (Errno::ENOENT)

Ruby can not find the file. Put the file in C:\ and try this:

browser.file_field(:name,'userfile').set("C:\\hi.docx")

Željko
--
filipin.eu

Al Snow

unread,
Aug 4, 2012, 8:56:28 AM8/4/12
to watir-...@googlegroups.com
Try "/"s instead of "\"s in the file path.


Date: Sat, 4 Aug 2012 18:05:50 +0530
Subject: Re: [wtr-general] Re: Handling a windows file upload dialog box
From: mani...@gmail.com
To: watir-...@googlegroups.com
--
Before posting, please read http://watir.com/support. In short: search before you ask, be nice.
 
watir-...@googlegroups.com
http://groups.google.com/group/watir-general

mani racha

unread,
Aug 6, 2012, 3:26:23 AM8/6/12
to watir-...@googlegroups.com, crapa...@yahoo.com.au

same error

Reply all
Reply to author
Forward
0 new messages