File upload with Selenium
In my Selenium tests I want to upload some files. Due to security restrictions it is by default not possible that a Javascript fills in a path in the respective input field. But fortunately, there exists a workaround:
a) The Mozilla must have the configuration option
“signed.applets.codebase_principal_support” set to the value “true”.
This allows non-signed scripts to request higher privileges.b) Selenium must request higher privileges which can be handled in
different places. To allow typing into file fields you can include this
call:netscape.security.PrivilegeManager.enablePrivilege(”UniversalFileRead”);
in the file selenium-api.js in function Selenium.prototype.doType. This
enables uploading local files.
This workaround works also with Firefox.




Would you be able to go into any detail about how to test uploading files(eg excel) into an on-line app using selenium and IE
Me again - is there any way to place the address of the file you are uploading into the text field - i tried type but got aunknown command error
@alex: Sorry, I am not able to say anything about IE as I do not use IE. Maybe you will have more luck in the selenium forums: http://forums.openqa.org/index.jspa
By default, it is not possible to place the address of the file you want to upload into the text field with “type” due to security restrictions, hence the workaround ;-) But I think this workaround is Mozilla-specific and does not work with IE…
Please help me about file upload section. I am trying to upload a file and store it into a folder not database.
another how to use GD using cakephp? please help me.my all try in vain.
@Surajit: Have a look at http://php.net/manual/en/features.file-upload.php and my article about file uploads: http://cakebaker.42dh.com/2006/04/15/file-upload-with-cakephp/
I don’t have experience with GD, but maybe someone in the google group (http://groups.google.com/group/cake-php) has experience with it.
Hi ,
I have a browse button in my html which uploads the pdf file. used the command type which dosen’t work.
I also performed these steps:
1)Added pref(”signed.applets.codebase_principal_support”, true); into all.js file under firefox folder
C:\Program Files\Mozilla Firefox\greprefs.
2)Added to Selenium.prototype.doType = function(locator, value) {
netscape.security.PrivilegeManager.enablePrivilege(’UniversalFileRead’);
Still it doesn’t work, please let me know what am I doing wrong?
Thanks,
With regards,
Manisha
@Manisha: I am not sure if this hack still works as this article is quite old, and I have switched to the Selenium IDE in the meantime. With the Selenium IDE, file uploads work without problems.
Hope that helps.
I know it’s an old thread, but I thought I’d weigh in because I was looking for a solution to this problem and found it here.
In addition to the IDE, I was able to upload files with Selenium Core v0.8.2 by using the hack as instructed. The relevant section of selenium-api.js looks like this:
Selenium.prototype.doType = function(locator, value) {
/**
* Sets the value of an input field, as though you typed it in.
*
* Can also be used to set the value of combo boxes, check boxes, etc. In these cases,
* value should be the value of the option selected, not the visible text.
*
* @param locator an element locator
* @param value the value to type
*/
netscape.security.PrivilegeManager.enablePrivilege(”UniversalFileRead”);
if (this.browserbot.controlKeyDown || this.browserbot.altKeyDown || this.browserbot.metaKeyDown) {
throw new SeleniumError(”type not supported immediately after call to controlKeyDown() or altKeyDown() or metaKeyDown()”);
}
// TODO fail if it can’t be typed into.
var element = this.browserbot.findElement(locator);
if (this.browserbot.shiftKeyDown) {
value = new String(value).toUpperCase();
}
this.browserbot.replaceText(element, value);
};
Taylor Dorris
http://www.proace.com
@taylor: Thanks for this code snippet!