Issue Details (XML | Word | Printable)

Key: SEL-63
Type: Improvement Improvement
Status: Open Open
Priority: Major Major
Assignee: Jason Huggins
Reporter: Darrell DeBoer
Votes: 15
Watchers: 17
Operations

If you were logged in you would be able to see more operations.
Selenium

Support for <input type="file"/>

Created: 17/Mar/05 01:21 AM   Updated: 07/Sep/09 08:47 AM
Component/s: None
Affects Version/s: 0.2
Fix Version/s: None

File Attachments: None
Image Attachments:

1. Winter.jpg
(103 kB)


 Description  « Hide

We need a way to manipulate HTML controls of the type <input type="file"/> in Selenium.



Sort Order: Ascending order - Click to sort in descending order
Darrell DeBoer added a comment - 19/Mar/05 10:41 PM

This mail was sent by Christian Theune outlining a workaround on Mozilla:
http://lists.public.thoughtworks.org/pipermail/selenium-users/2005-March/000213.html


Dan Fabulich added a comment - 09/Nov/06 10:05 PM

This works in Selenium IDE and/or Selenium RC running in *chrome mode.


Dan Fabulich added a comment - 13/Nov/06 01:36 AM

I should add that except for Selenium IDE and/or Selenium RC, we really have no leads on this at all... it's a security restriction baked into JavaScript itself. There's no clever way to workaround it within pure JavaScript, so it really can't be fixed in Selenium Core.

Christian Theune's workaround is described here: http://forums.openqa.org/thread.jspa?messageID=1368#1368

It's basically the same thing as going into *chrome mode.

Note that here at my work our trick to workaround this on other browsers was to focus on the file input field and send keystroke events to it using OS-level tools. (Selenium RC could use java.awt.Robot, for example.) Selenium RC could do this, but Selenium Core certainly couldn't.


Jason Huggins added a comment - 23/Jul/07 11:25 PM

Selenium Core could use java.awt.Robot if we compile and bundle a self-signed applet with Core. The user would have to approve the applet at least once with Core... Or install our certificate before running tests...


SunithaV added a comment - 10/Sep/07 02:31 AM

Hi Dan,

Can you elaborate on the workaround for entering data into a filed whose type=file.
I am able to work on chrome browser. What about other browsers like IE which is very important to be tested for many web applications?
I am usign Selenium RC with Java

Regards
Sunitha


David Wing added a comment - 04/Feb/08 10:54 PM

I have found a work around that involve running in the HTA. This method works about 97% of the time so it is not perfect.
To use this method you create an user-extension that instantiates the wscript.shell object and use the appactivate and sendkeys to type into the field.

before this method can work you need to make sure that the input box has input focus.

I would like to have another method for this, but this will for for the mean time.

Selenium.prototype.doSendKeys = function(windowname, keys) {
try

{ var objShell = new ActiveXObject("wscript.shell"); objShell.AppActivate(windowname); objShell.SendKeys(keys); }

catch(w)

{ throw new Error( 'sendkey did something' + w ); }

objShell = null;
};


David Delbecq added a comment - 10/Mar/08 05:18 AM

Just a stupid suggestion:

except for selenium IDE, testing using selenium makes it act as a layer between tested site and browser. The job of selenium server is to inject javascript in response to handle selenium testing.

A typical testing using selenium is like this for a textfield:

selenium.type("form:url", "http://www.google.test");
selenium.click("form:update");

This will make server instruct browser to do those 2 manipulation in javascript (type something then click something)
Suppose we want to upload the a file. Imagine selenium has an additionnal method:

byte[] datas = ....;
String contentType = "text/pdf";
String filename = "filename/that/could/be/usefull/but/is/not/read.pdf"
selenium.upload("form:file",contentType,filename,datas); // ask selenium server to inject an uploaded file upon next POST
selenium.type("form:url", "http://www.google.test");
selenium.click("form:update");

This would be crossbrowser compatible, wouldn't need to circumvent javascript securities (this is done selenium server side, not javascript side) and wouldn't need some files at specific location on testing machine (the file uploaded could be randomly generated by unit test driving selenium, or loaded from a database of tests of whatever).

Disadvantage: wouldn't work on selenium IDE, as it would require a selenium server to do the injection operation. But would work with any selenium client available (java, php, ...) as long as client implement this additional method.


David Delbecq added a comment - 10/Mar/08 05:21 AM

To be clear on my previous post, the idea is to have selenium server not only alter response by injecting javascript in it, but also to alter multipart request, by inject uploaded file in it. So for file uploads, testing woudl'nt be done from javascript but at submit time. Woudln't be perfect but could at least test behaviour of server facing a file upload. (Wouldn't help testing client's reaction to selecting a file however)


Marcelo Vaccaro added a comment - 22/Mar/08 04:49 AM

Dear David Wing,

I saw you previous post. The sendKeys command seems to be working but I´m not being able to make sure that the input box has input focus.
When i use click it opens the browse window instead of setting the focus on the input box.

Who are you setting the focus to the input box?

Thanks,
Marcelo


Yuri added a comment - 26/Jun/08 07:41 AM

Marcelo,
Try using selenium.focus() method. It works fine in my case.


aditya added a comment - 07/Sep/09 08:47 AM

Hi Sunitha,

Are you able to use type <input type="file"/> in Selenium IE.

If yes, Please let me know the solution.

Thanks in Advance.
Avnish