Having your tests upload files to the test application is something that becomes confusing when moving Selenium RC servers to different machines.
Browsers can only upload files from the local machine, but when the RC server (and consequently the browser) are on a different machine than the one running the test, this can be very hard to do.
Luckily, for this kind of situations, Selenium has the attach_file method which receives both a locator and a URL as parameters, then the RC Server takes care of downloading the file to the test machine at a temporary location and then attaching the file completing with this path in the desired field.
Here’s the reference from Selenium’s documentation:
In [5]: sel.attach_file?
Definition: a.attach_file(self, fieldLocator, fileLocator)
Docstring:
Sets a file input (upload) field to the file listed in fileLocator
'fieldLocator' is an element locator
'fileLocator' is a URL pointing to the specified file.
Before the file can be set in the input field (fieldLocator), Selenium RC may need to transfer the file to the local machine before attaching the file in a web page form.
This is common in selenium grid configurations where the RC server driving the browser is not the same machine that started the test.
Supported Browsers: Firefox ("*chrome") only.
Keep in mind that for using this method the files to upload will have to be placed in a public URL. However, if you don’t want them to be 100% public, you can still keep them safe using basic HTTP Auth and get them using the auth information in the same URL.
Here’s an example usage of the command in python:
sel.attach_file("css=input[type=file]", "http://url.com/file.txt")
Some caveats in Selenium’s implementation, is that this only works on firefox and that also the file must be placed on top level in the URL, so using the following URL will not work:
http://saucelabs.com/subdirectory/subdirectory2/file.txt
while the following will:
http://saucelabs.com/file.txt
In Sauce OnDemand, we took care of fixing both issues + adding ftp support too, so if you used Sauce OnDemand, just put your files in a public server (both HTTP or FTP) and then just use attach_file to upload them.
Hope you find this useful, and if you need more info, let us know in the comments.
Related posts:
Selenium Tips: Taking ScreenShots on the Server
Selenium Tips: Improving your waiting skills
Selenium Tips: Infinite Loops Take Forever
Selenium Tips: Start improving your locators
Running your Selenium tests in parallel: Python

I’ve started switching over from Webrat to Capybara but I noticed that attach_file in Capybara doesn’t support URLs. Is there a solution for this?
If you’re using Python, with a little work, you can use the SimpleHTTPServer and SocketServer module from the standard library to spin up a server to respond to requests from attach_file. Doing so makes your tests self-contained.
You need to use SocketServer.ThreadingMixIn run the server in threads separate from your tests, otherwise it blocks. Also you can sub-class SimpleHTTPServer.SimpleHTTPRequestHandler and override its translate_path method to serve files from the directory of your choice.