File upload using selenium webdriver in a form...

11,514 views
Skip to first unread message

webdriver user

unread,
Sep 13, 2012, 2:03:26 AM9/13/12
to seleniu...@googlegroups.com
Hi Selenium folks,   

I have asked this question before , but have found no success with this. I need to upload a file into the system
Here are the steps

1) Click on add files button----- a native windows file upload window opens
2) need to select the file and click on open
3) the path of the file is now filled in- now, I have to click "start upload" button
4) upload completes.


Am using windows 7 OS and selenium webdriver 2.0 with Java. Firefox 10.0
When the native windows file upload window opens, my script does not go forward...just hangs there.

Need the steps to rectify this. I found from the HTML that this is a FORM.   Sample webdriver code would help.


Here is the HTML of my application page where am doing the file upload:

<div id="masterUploadContainer">
<form>
<div id="uploader" style="position: relative;">
<div class="plupload_wrapper plupload_scroll">
<div id="uploader_container" class="plupload_container" title="Using runtime: html4">
<div class="plupload">
</div>
<input id="uploader_count" type="hidden" value="1" name="uploader_count">
</div>
<form id="form_p176v33rpq1qvato218ohcb01e4h5" method="post" enctype="multipart/form-data" encoding="multipart/form-data" target="p176v31j7d1dsa1irr1gl0cgg56o0_iframe" style="position: absolute; overflow: hidden; top: 151px; left: 16px; width: 76px; height: 22px; z-index: -1;">
<input id="input_p176v33rpq1qvato218ohcb01e4h5" type="file" accept="" size="1" style="width: 100%; height: 100%; opacity: 0; font-size: 999px;">
</form>
</div>
</form>
</div>


Chaitanya

unread,
Sep 13, 2012, 2:12:47 AM9/13/12
to seleniu...@googlegroups.com
Why Cant U you use AutoIt for the file Upload


Thanks
Chaitanya

Debasish Dutta

unread,
Sep 13, 2012, 2:14:34 AM9/13/12
to seleniu...@googlegroups.com
how we can use AutoIT? can u plz tell the process??
--
You received this message because you are subscribed to the Google
Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to
selenium-user...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msg/selenium-users/-/lGa-jvyE1xMJ.

For more options, visit https://groups.google.com/groups/opt_out.

webdriver user

unread,
Sep 13, 2012, 2:15:13 AM9/13/12
to seleniu...@googlegroups.com
Dont want to use AutoIT for the moment...want to explore all the possibilities using webdriver first.
Not ruling out AutoIt though...

any help folks?

cheers
Rashmi

jeevan

unread,
Sep 13, 2012, 2:15:06 AM9/13/12
to seleniu...@googlegroups.com
Once you click on Add Files Button,  a native windows file upload window opens up. To handle this window:

AutoIT.

Example:

WinActivate("Choose file");
Local $file = "FileLocation"
ControlSetText("Choose file", "", "Edit1", $file )
ControlClick("Choose file", "", "Button2")


You  can do basic R & D about AutoIT.

Thanks,
Jeevan.


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/ccaovBk7A58J.

Peter Gale

unread,
Sep 13, 2012, 2:15:38 AM9/13/12
to Selenium Users
For uploading files you should be able to just use sendkeys to send the file's full path name to the input element triggering the upload.

Have you tried that?


Date: Wed, 12 Sep 2012 23:03:26 -0700
From: rashm...@gmail.com
To: seleniu...@googlegroups.com
Subject: [selenium-users] File upload using selenium webdriver in a form...

Chaitanya

unread,
Sep 13, 2012, 2:18:07 AM9/13/12
to seleniu...@googlegroups.com

jeevan

unread,
Sep 13, 2012, 2:19:18 AM9/13/12
to seleniu...@googlegroups.com
As Peter said if Upload file text box is part of webpage then you can use sendKeys else have to look for the different option like AutoIT.

Thanks,
Jeevan.

Peter Gale

unread,
Sep 13, 2012, 2:20:21 AM9/13/12
to Selenium Users
Guys ... there is a pure Slenium solution to uploading files and this is a Slenium forum, so can we stick to exploring the Selenium route before pushing other options?


Date: Wed, 12 Sep 2012 23:18:07 -0700
From: chaitu.a...@gmail.com
To: seleniu...@googlegroups.com
Subject: Re: [selenium-users] Re: File upload using selenium webdriver in a form...
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/_hsEwoQgJo8J.

Debasish Dutta

unread,
Sep 13, 2012, 2:21:38 AM9/13/12
to seleniu...@googlegroups.com
I m agree with peter. sendkeys will work for uploading file.

jeevan

unread,
Sep 13, 2012, 2:22:40 AM9/13/12
to seleniu...@googlegroups.com
Sure Peter.

webdriver user

unread,
Sep 13, 2012, 2:23:20 AM9/13/12
to seleniu...@googlegroups.com
Hey {eter I have tried sendkeys option as well....

with that, it does open the windows file upload window and does not write the path in the window. Am unsure how to specify the path- for ex: in windows 7 OS, how should the path be specified...forward slash or 4 backward slashes?

can you please give me a sample code?

Thanks
Rashmi

webdriver user

unread,
Sep 13, 2012, 2:24:56 AM9/13/12
to seleniu...@googlegroups.com
Exactly my point...AutoIT would be my last option...I want to explore all selenium webdriver options first...

Thanks
Rashmi

Debasish Dutta

unread,
Sep 13, 2012, 2:26:29 AM9/13/12
to seleniu...@googlegroups.com
@ rashmi

sendkeys will work. i have tried with sendkeys option it is working for me.
> https://groups.google.com/d/msg/selenium-users/-/vdS6xxoErkwJ.

Peter Gale

unread,
Sep 13, 2012, 2:27:04 AM9/13/12
to Selenium Users
Using sendkeys shouldn't open a windows dialog. And you cannot interact with windows dialog in Selenium.

Using forward slashes in the filename should work and seems to be much more readable to my mind than having to escape the backslashes with extra backslashes.

Show us your code for uploading the file with sendkeys and we can have a look to see what's wrong.



Date: Wed, 12 Sep 2012 23:23:20 -0700
From: rashm...@gmail.com
To: seleniu...@googlegroups.com
Subject: Re: [selenium-users] File upload using selenium webdriver in a form...
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/hjwgqhwZ12gJ.

Anji Prassana

unread,
Sep 13, 2012, 2:28:18 AM9/13/12
to seleniu...@googlegroups.com
Peter, I hope, The input field in their webapplication, which takes the path of a file to upload was Non-Editable field. So, we can't directly set the text into this unless go for browse option and pick a file from that File Upload native window.
 
Hi 'Webdriver User' [We need to identify you like this as your name not there :)],
 
   As some people alreasy commented, you can handle it easily via Autoit. But ,I understood your intention that don't go for AutoIt unless no such alternate exists which can handle through a program itself. I am not sure [because i also used autoit to handle these in my application] but I hope that you can achieve it via Javas Robot class.

 
On Thu, Sep 13, 2012 at 11:45 AM, Peter Gale <peterjef...@hotmail.co.uk> wrote:



--
Thanks&Regards
Anjaneyulu P
"The way you see the things is the way to think and is the way you react upon!!"

webdriver user

unread,
Sep 13, 2012, 2:33:19 AM9/13/12
to seleniu...@googlegroups.com
Here it is:



    List<WebElement> uploadElements = driver.findElements(By.className("plupload_buttons"));
       
            for (WebElement uploadElement : uploadElements) {   
             
                uploadElement.findElement(By.id("uploader_browse")).click();

                uploadElement.sendKeys("C:\\Users\\Public\\Pictures\\Sample Pictures\\Chrysanthemum.jpg");
                               

Have tried this option too:
                               
                WebElement fileInput = driver.findElement(By.id("uploader_browse"));
                fileInput.sendKeys("C:\\Users\\Public\\Pictures\\Sample Pictures\\Chrysanthemum.jpg");
and this:
                //fileInput.sendKeys("C:/Users/Demo/Desktop/today.txt");
               
               
            }

       plz let me know what is missing....

cheers

Peter Gale

unread,
Sep 13, 2012, 2:33:57 AM9/13/12
to Selenium Users
It might be, Anji, but he also taks about an "Add Files" button that I can't see, so I tdon't think we have the full picture yet, do we,

And even if the element he needs is hidden, he could always unhide it with javascript for the purposes of the upload, couldn't he?

Or get the developers to make it permanently unhidden.


Date: Thu, 13 Sep 2012 11:58:18 +0530
Subject: Re: [selenium-users] File upload using selenium webdriver in a form...
From: anji...@gmail.com
To: seleniu...@googlegroups.com

webdriver user

unread,
Sep 13, 2012, 2:37:33 AM9/13/12
to seleniu...@googlegroups.com
Hi,
  If there were an input field in the application itself it would have been easier...but it is not so. the case is , I have to click on add files button( which I can successfully) this takes us to the windows native file open window, where am not able to put the path and then click on open button...

nothing is hidden...i just need to input the path in the native window which opens and click open...

thanks
Rashmi

Hari

unread,
Sep 13, 2012, 2:37:29 AM9/13/12
to seleniu...@googlegroups.com
Hi ,

 By Selenium Webdriver

driver.findElement(By.cssSelector("#txtFileName")).sendKeys("\\\\192.168.128.79\\Share\\VALID\\DQI\\SampleI.txt");

IF u want to Use the AutoIT mean

1. Record the the part of the clicking the Browse Button and select the file.
2. Convert the AutoIt script into .exe.
3. Use the below script

String[] commands = new String[]{};
commands = new String[]{"C:\\Documents and Settings\\axtst079\\Desktop\\Hari1.exe"}; //location of the autoit executable
 Runtime.getRuntime().exec(commands);

Regards,
Hari

Peter Gale

unread,
Sep 13, 2012, 2:39:16 AM9/13/12
to Selenium Users
I'd think you just need:

  driver.findElement(By.className("plupload_buttons")).sendkeys("C:/Users/Demo/Desktop/today.txt");

Though, I can't see the element with class name "plupload_buttons" in your html so I'm assuming that this is the right element we need.


Date: Wed, 12 Sep 2012 23:33:19 -0700
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/fApheWmEuakJ.

webdriver user

unread,
Sep 13, 2012, 2:49:43 AM9/13/12
to seleniu...@googlegroups.com
"plupload_buttons" is the Add Files button in the application.
My code does click on the add files button in debug mode, but not in run mode( surprising) but again the same problem of inserting the file path and then clicking on open button in that dialog is bothering me...

does sendKeys ( path) - send the path and click the open button as well?

webdriver user

unread,
Sep 13, 2012, 3:07:30 AM9/13/12
to seleniu...@googlegroups.com
any help folks???

Anji Prassana

unread,
Sep 13, 2012, 3:38:02 AM9/13/12
to seleniu...@googlegroups.com
Hi Rashmi,
  Your question is fine but we can't handle those with selenium.As i said try to explore Java  Robot Class to find any such. I assumed that your UI as in attached screenshot.
 
 As you said if input field exists it's easier.But, I said no. Mostly, The input fields in your application which takes paths through File Open window are not editable.I mean, you can't type in that field just as you did for some other form fields <input type="text"> kind of fields.But, <input type="browse"> kind of fields are mostly non-editable so,you can't enter the file path directly into this field [It's the nature/behavior of such a field].
 
 

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/uiiMDpko048J.

For more options, visit https://groups.google.com/groups/opt_out.
 
 
Browse_FileOpen.JPG

Peter Gale

unread,
Sep 13, 2012, 3:57:56 AM9/13/12
to Selenium Users
Rashmi

Please be patient. We have other things to do apart from just answer quereies here.

I can't see "plupload_buttons" or an "Add files" button mentioned in you html, so you need to supply us with full copy of you html including this element.

The "hidden" input may (or may not) be irrelevant.

>does sendKeys ( path) - send the path and click the open button as well?

With the selenium approach you will bypass teh windows upload dialo


Anji

Are you working with Rashmi? You seem to be telling us about details on Rashmi's application that he has told us himself.
 



Date: Thu, 13 Sep 2012 00:07:30 -0700
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/wd6Ayet2voUJ.

Krishnan Mahadevan

unread,
Sep 13, 2012, 3:58:55 AM9/13/12
to seleniu...@googlegroups.com
Peter,
Rashmi would be a "she" :)

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

Peter Gale

unread,
Sep 13, 2012, 4:02:04 AM9/13/12
to Selenium Users
Ok ... maybe I need lessons in Indian names! (Or just remember to be less gender specific next time)


Date: Thu, 13 Sep 2012 13:28:55 +0530

Subject: Re: [selenium-users] File upload using selenium webdriver in a form...

Anji Prassana

unread,
Sep 13, 2012, 4:25:58 AM9/13/12
to seleniu...@googlegroups.com

>>Anji

>>Are you working with Rashmi? You seem to be telling us about details on Rashmi's application that he has told us himself.
 Hi peter,
   I am not part of Rashmi project. But, As file Browse feature is generic and common in most of the applications, I am guessing as such. Anyhow, she need to share us the screenshot of his application to help her better.
 
But, Peter, her Question is straightfarward and geneal for which most of the threads are already there i.e., How to handle native windows via selenium??And, our answer is also simple.We can't handle with the use of selenium. So, try other alternates like, Autoit or java Robot Class or few other which you may used in your project.
 
But, she wants to handle those with selenium/Java.But, Till now, I didn't see any such API calls in Java or Selenium other than Autoit and Robot class.

Peter Gale

unread,
Sep 13, 2012, 4:47:42 AM9/13/12
to Selenium Users
Anji

The real issue for Rashmi is why she can't use the Selenium file upload method. That would bypass the need to using windows dialogs altogether and be a much better solution.

Peter


Date: Thu, 13 Sep 2012 13:55:58 +0530

Subject: Re: [selenium-users] File upload using selenium webdriver in a form...

Manoj Hans

unread,
Sep 13, 2012, 5:00:46 AM9/13/12
to seleniu...@googlegroups.com
sendKeys("Location Path") is very good to upload file but here i analyzed lot of folks dont know how to use the same.

For Ex-- They first click on the button and then use sendkeys (It means click will open dialog after that sendkeys wont able to upload the file )

But it should be use without click on upload button (driver.findElement(By.id(upload button id)).sendKeys(Location Path)).



--Manoj Hans

Peter Gale

unread,
Sep 13, 2012, 5:04:11 AM9/13/12
to Selenium Users
Tru ... but the first problem here seems to be identifying exactly which element to use the sendkeys method on.


Date: Thu, 13 Sep 2012 02:00:46 -0700
From: hman...@gmail.com
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/XmpfjladjNAJ.

jeevan

unread,
Sep 13, 2012, 5:08:52 AM9/13/12
to seleniu...@googlegroups.com
Rashmi,

We automated 200 test cases of same type with different approach since Selenium looses focus on Windows popups. If the text box is not editable then in no way you can handle the Native window with Selenium. You have to go for other alternatives.

Thanks,
Jeevan.

Peter Gale

unread,
Sep 13, 2012, 5:15:45 AM9/13/12
to Selenium Users
Jeevan

The element Rashmi needs to use sendkeys on will be the one called "add files" that she clicks on. If she can click on it she can use Selenium's send keys on it. We just don't know which element it is yet. So it is too ealry to write off any chance of a Selenium solution to this problem yet.

Peter


From: g1re...@gmail.com
Date: Thu, 13 Sep 2012 14:38:52 +0530

Subject: Re: [selenium-users] File upload using selenium webdriver in a form...

jeevan

unread,
Sep 13, 2012, 5:41:09 AM9/13/12
to seleniu...@googlegroups.com
Correct Peter, i will agree with you. If she clicks on that then Selenium very well handle the same.

Jim Evans

unread,
Sep 13, 2012, 8:46:21 AM9/13/12
to seleniu...@googlegroups.com
I'm going to regret replying to this thread, but I can't seem to resist trying to set the record straight. WebDriver is perfectly capable of automating standard HTML file uploads. There is no need to use AutoIt, or Java Robot classes, or anything else outside the library. By "standard HTML file uploads," that means an element that looks similar to this on the page:

<input id="uploader" type="file" />

The "type" attribute is the key here. Most browsers, absent styling, render this as a text box (sometimes disabled), along with a button labeled "Browse" or some such. The correct way to automate this is with the sendKeys() method with the path to the file to be uploaded. Full stop. A call to the click() method is not required.

In some browser drivers, sendKeys() will invoke the native file selection dialog, fill in the file name, and dismiss it; in others it will bypass the native dialog altogether. Either way, the WebDriver is perfectly capable of handling it.

Problems start to arise, however, when website developers start to think that the standard HTML file upload control isn't functional enough, or isn't pretty enough, or whatever other reason they may come up with for trying to reinvent the wheel. In those cases, and only those cases, where the page isn't using an <input> method where the type attribute is set to "file", should you need to explore options outside of WebDriver.

navneet shrivastava

unread,
Sep 13, 2012, 8:54:22 AM9/13/12
to seleniu...@googlegroups.com
Jim has given the ans.... no need to click or even use AutoIT for this... simply use sendkeys and type (in case of RC) and webdriver should handle it... nothing more needs to be done...

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/WU0kO-z7G9wJ.

Anji Prassana

unread,
Sep 13, 2012, 8:57:01 AM9/13/12
to seleniu...@googlegroups.com
Hi Evans,
  Thanks for enlighten us with your interesting comment.However, one of the statement in your comment stated "In some browser drivers, sendKeys() will invoke the native file selection dialog, fill in the file name, and dismiss it; in others it will bypass the native dialog altogether. Either way, the WebDriver is perfectly capable of handling it".
 
You said that in some browsers sendKeys() will open native file dialog and we need to fill the filename and dismiss it.But, I just wonder how with the selenium we fill the filename field of a native file dialog and dismiss the dialog? Can you please elaborate on how to fill the filename field of a native dialog and dismiss the file dialog??

On Thu, Sep 13, 2012 at 6:16 PM, Jim Evans <james.h....@gmail.com> wrote:
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/WU0kO-z7G9wJ.

Peter Gale

unread,
Sep 13, 2012, 9:12:36 AM9/13/12
to Selenium Users
Anji


> You said that in some browsers sendKeys() will open native file dialog and we need to fill the filename and dismiss it.

No ... Jim said:

"In some browser drivers, sendKeys() will invoke the native file selection dialog, fill in the file name, and dismiss it;"

We don't have to do anything in such cases - WebDriver would do it for us.

Peter


Date: Thu, 13 Sep 2012 18:27:01 +0530

Subject: Re: [selenium-users] File upload using selenium webdriver in a form...
From: anji...@gmail.com
To: seleniu...@googlegroups.com

Anji Prassana

unread,
Sep 14, 2012, 12:43:54 AM9/14/12
to seleniu...@googlegroups.com
 >>We don't have to do anything in such cases - WebDriver would do it for us.
 If WebDriver can do it then it's pretty good.However, I have to check this interesting thing then..

jeevan

unread,
Sep 14, 2012, 12:53:42 AM9/14/12
to seleniu...@googlegroups.com
Rashmi just for curiosity to know...will you be able to get through this scenario?

Thanks,
Jeevan.

Rashmi Rohit

unread,
Sep 14, 2012, 1:41:37 AM9/14/12
to seleniu...@googlegroups.com
I was quite skeptical about Evans answer here...Not sure how the
selenium will fill int he path name and also dismiss the native window
with just sendKeys(); I tried exploring this option but didn't
work....

all the form members opine just one thing, that is sendKeys ()...which
in many cases works , but in my web application, the native window has
to open when I click on Add Files button. There is no input area in my
application where the path can be directly entered and sendKeys would
work...the add files button has to open the window and when this
happens, selenium webdriver loses focus and can't type in the file
name and click on open button in the window...that is the problem
which is happening...Attached is my application page and HTML of the
page as well...

how can this scenario be handled? is this any environment issue- am
using FF 10.0 and windows 7

Thanks
screencapture.PNG
html.docx

Peter Gale

unread,
Sep 14, 2012, 2:46:43 AM9/14/12
to Selenium Users
Rashmi

Jim answer is quite clear and easy enough to understand if you read it carefully. Your skepticism comes from fuzzy thinking and misunderstanding what he has said.

WebDriver will be able to use sendkeys() when the developers have used the standard html method of an input element with a "type" attribute set to the value "file". Now finally have your full html to look at I can find your "add files" button as well as a related one called "Start Upload" - we haven't seen these before now, but now we have, it can be seen that they are not <input> tags and neither do they (or anything else) have a "type" attribute with a value of file.

So we can finally say that WebDriver WILL NOT be able to handle the file upload for your application, in any browser.

The point of WebDriver populating the Windows O/S level related only to cases where WebDriver CAN handle the file upload with sendkeys (which it can't for you) and in certain browsers only (probably not the one you are using any way), not in ALL browsers.

Your page seems to be a case as Jim described where the developers have chosen not to go with the standard html upload facility (whcih WebDriver CAN handle) with a custom one that WebDriver CANNOT handle, since it directly calls O/S level dialogs that WebDriver does not directly work with.

You have two options ... comlpain to the developers that this is unecessary and wasteful code that will have an extra maintenance cost etc and that is quitre adequate html funcitonality available out of the box.

Or you can chose to work with non-Selenium tools like Java Robot class or AutoIT for which some links/help has been provided already. However, since this is now no-longer a Slenium related issue you should seek support for those tools elsewhere.

Peter

> Date: Thu, 13 Sep 2012 22:41:37 -0700

> Subject: Re: [selenium-users] File upload using selenium webdriver in a form...

Anji Prassana

unread,
Sep 14, 2012, 3:13:36 AM9/14/12
to seleniu...@googlegroups.com
>>You have two options ... comlpain to the developers that this is unecessary and wasteful >>code that will have an extra maintenance cost etc and that is quitre adequate html >>funcitonality available out of the box.
 
Hi Peter,
   Your point is OK. But, the developers also can't do anything outside the tool/framework they are using. It seems to be Application is developed using GXT/GWT framework. So, the elements whatever we are seeing in DOM tree are totally framework dependent and thery are visible as is defined under the framework to have a rich look and feel. Not only GXT/GWT lot of such tools like JSF/Struts etc using for design of presentation tier of an application may have this kinda functionality as these are the tools which are evolved from the standard HTML to make the elements more rich.
 
So, I vote for your second alternate go with Robot/Autoit etc..

Peter Gale

unread,
Sep 14, 2012, 4:50:32 AM9/14/12
to Selenium Users
While tools might have facilities to add to the basic html offerings, there would seem to being something wrong if they take away some of the basic functionality too.

If anyone chooses a customised tool, there should be little surprise if they end up needing customised tools to automate it.


Date: Fri, 14 Sep 2012 12:43:36 +0530

Mark Collin

unread,
Sep 15, 2012, 7:05:35 AM9/15/12
to seleniu...@googlegroups.com
His name is actually Jim (Evans is his surname) and he is one of the core
development team for Selenium (He wrote the Internet Explorer driver), he
knows what he is talking about.

If you had read through Jim's comment correctly you will have seen that he
said that .sendKeys() works when a <input type="file"> is used in your HTML.
Hand crafted custom methods using other technologies will not be supported.
In your case you are going to have to talk to your devs and find out how the
upload functionality works, looking at the HTML you just have a couple of
anchors and there is no obvious JavaScript hook. I assume there is
something like jQuery binding an action to these elements when the page is
loaded and performing some magic to make the upload work.

Mark Collin

unread,
Sep 15, 2012, 7:07:06 AM9/15/12
to seleniu...@googlegroups.com

Using the GWT/GXT framework does not prevent your developers from using an <input type=”file”> in your page.  Suggesting it does is frankly ridiculous.

Nick

unread,
Nov 28, 2012, 7:59:31 PM11/28/12
to seleniu...@googlegroups.com
You can not automate that step with Selenium/Webdriver. What you can do, you can hack file upload to bypass file selection by injecting JS which would test just upload routines but not the user steps of file selection. Actually that can be quite tricky hack if your application uses flash or java applet uploader

On Thursday, November 29, 2012 7:58:41 AM UTC+11, Ivan Grama wrote:
I agree with Mark.
Our devs use "plupload" library as well which means there is NO <input type="file"> and you can not just use "senKeys" method as couple people were trying to tell others in this thread.
As I can see "plupload" lib becomes popular among devs probably because its high security. It receives specific params from a particular object (flash, js etc) and then jQuery binding upload action as Mark described above.

Many people in this thread recommends to use Autoit or Robot AWT.
1. I have used Autoit before and in case when you run your tests on one machine and execute them on another (which is common thing nowadays with CI) this tool becomes totally useless.
Plus it works only for Windows so no cross platform testing.
2. Use Robot AWT is more flexible way but in case when you have to run your tests remotely you will need to run an additional server on remote machine which is not convenient at all but anyway better than autoit.

I would be very appreciated if somebody will share his/her experience of handling such situations.

Vishal Mishra

unread,
Nov 29, 2012, 1:40:17 AM11/29/12
to seleniu...@googlegroups.com
You can use JSON wire Protocol for Uploading Please google it for exact solution.

Pushpraj Singh

unread,
Jul 11, 2013, 7:58:40 AM7/11/13
to seleniu...@googlegroups.com

Hello Everyone ,

.sendKeys("absolute path to the file you want to upload via webdriver");
worked for me but not when I have to upload the file via flashbutton. Can flashselenium-java-client-extension-1.0.jar would be a help, if yes how can I use it to upload file.
Please see the screenshot :

Pk

unread,
Jul 25, 2013, 2:33:09 AM7/25/13
to seleniu...@googlegroups.com
Hi Every one the Autoit is also not working for file upload the auto it script is not executed .please tell the correct way to upload a file by using selenium.
WebBrowser iam using is:MozilaFireFox
Thanks
Pk

adem sandeep

unread,
Jul 26, 2013, 3:14:52 AM7/26/13
to seleniu...@googlegroups.com
I have an issue with Plupload control. If windows is minimized. It's not bale to click on the Add files. Some of the times it's working fine. Any one faced the same issue with this control.

Darshna Gurjar

unread,
Oct 14, 2013, 6:53:51 PM10/14/13
to seleniu...@googlegroups.com, peterjef...@hotmail.co.uk
Hi I am trying to upload a file in Gubuntu with element.sendkeys();

It doesn't do anything. I am using citc client and the file I am uploading is not local but in the some directory from citc client as data.

Any clue?


On Thursday, September 13, 2012 2:15:46 AM UTC-4, Peter Gale wrote:
For uploading files you should be able to just use sendkeys to send the file's full path name to the input element triggering the upload.

Have you tried that?


Date: Wed, 12 Sep 2012 23:03:26 -0700
From: rashm...@gmail.com
To: seleniu...@googlegroups.com
Subject: [selenium-users] File upload using selenium webdriver in a form...
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/ccaovBk7A58J.

Pavol Kianicka

unread,
Oct 18, 2013, 10:22:44 AM10/18/13
to seleniu...@googlegroups.com
Hey guys,

I'm preparing a prototypish script in Selenium IDE 2.4.0 to be used in FF 23.0 and have a trouble with using sendKyes method to upload a file to our EXT.NET web application.
The page code is like this:
<input id="cphPluginContent_formUserEdit_fuCertificateUpload" class="x-form-text x-form-field x-form-file-text" type="text" autocomplete="off" size="20" readonly="" style="width: 386px;"></input>
<input id="cphPluginContent_formUserEdit_fuCertificateUpload-file" class="x-form-file" type="file" size="1" name="cphPluginContent_formUserEdit_fuCertificateUpload-file" style="width: 86px;"></input>

and my Selenium IDE script command that's not working is like this:
sendKeys(//input[@id='cphPluginContent_formUserEdit_fuCertificateUpload-file'], c:/Projects/soapUI/Certificates/certificate.cer)

The <input> element of type="file" is actually a button that opens Windows OS File Upload dialog after mouse click.

Do you have any clue what I may be doing wrong? Thanks for any suffestions.
Pavol

Gadigeppa Jattennavar

unread,
Jul 9, 2014, 10:16:10 AM7/9/14
to seleniu...@googlegroups.com

When you click on ‘Choose File’ button, OS native file select dialog will be opened. This dialog will not be recognized by your driver, so when uploading any file you should never click on ‘Choose File’ button. Instead, use sendkeys to select the file,

WebElement El = driver.findElement(By.id("'fileUploadField'"));
El.sendKeys("c:\\temp\\test.txt");

This will select your file without having to select it through file select dialog. This works flawlessly across all supported drivers.

If you are running your test on grid then you should let your remote driver know that the file is residing on local machine and not remote machine. This can be achieved by setting LocalFileDetector for RemoteWebElement,

WebElement El = driver.findElement(By.id("'fileUploadField'"));
((RemoteWebElement) El ).setFileDetector(new LocalFileDetector());
El.sendKeys("c:\\temp\\test.txt");


Here you are setting local file detector for file upload element, so whenever you use sendkeys on this element, your RemoteWebDriver uses this file detector object to detect the file. If the file is detected then it will be base64 encoded and uploaded to remote server through JSON Wire Protocol and the remote fixed path will be selected as a file path.

Please check my blog http://muthutechno.wordpress.com/2014/07/09/uploading-files-in-selenium-webdriver/

On Thursday, September 13, 2012 11:33:26 AM UTC+5:30, webdriver user wrote:

Serguei Kouzmine

unread,
Aug 24, 2014, 9:14:43 PM8/24/14
to seleniu...@googlegroups.com
9:11 PM (less than a minute ago)
Hello
I developed a code in C# to deal with download dialogs on Windows: set the local file name  / path. save the file. Please look at  the article, code is provided too,
http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=138391&aid=799161#54C724BE37D04CE0AD9584606ACF5560


Thanks,

Serguei Kouzmine
- show quoted text -
141.png
144.png

Assurance Quality

unread,
Dec 6, 2019, 11:11:03 PM12/6/19
to Selenium Users

Abhijeet Singh

unread,
Dec 9, 2019, 6:59:22 AM12/9/19
to Selenium Users
Hi Selenium Folks,

There is a free video for webdriver, you can see and solve your problem.

Reply all
Reply to author
Forward
Message has been deleted
0 new messages