Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using Selenium RC and Java and I need to automate the file upload feature.I tried a lot, Clicking on Browse button is not executing and rather getting stuck. I tried in FireFox but to no avail.

Below is my code:I used different commands to load file "type" & "AttachFile".pls can any one help me how to upload a file from "File Upload window".

RemoteControlConfiguration rcc =new RemoteControlConfiguration();
        SeleniumServer ss = new SeleniumServer(rcc);

DefaultSelenium  browser = new DefaultSelenium("localhost" , 3333 , "*firefox" ,"http://");

//Used type command
             browser.type("id=upload-file-input", "C:\\Documents and Settings\\Home\\Desktop\\dropdown.jpg");

//Used AttachFile command
  browser.attachFile("id=upload-file-input","C:\\Documents and Settings\\Home\\Desktop\\dropdown.jpg");

//Used Runtime command
    Runtime.getRuntime().exec("C:\\Documents and Settings\\Home\\Desktop\\dropdown.jpg");![enter image description here][1]
share|improve this question
Can u Just post what kind of error message you are getting .. – selva Feb 7 '13 at 12:56

If the form is normal html form, you can skip opening the file upload dialog (which you don't need to test as hopefully you haven't implemented it yourself), and just enter the filename to the form field.

WebElement uploadInputField = browser.findElement(By.Id("upload-file-input"));
uploadInputField.sendKeys("C:\\Documents and Settings\\Home\\Desktop\\dropdown.jpg");
share|improve this answer
that's exactly correct. i use it all over the place in my tests. make sure you use the \\ instead of just a single \ – squeemish Feb 7 '13 at 19:29

According to this, the second parameter to the browser.attachFile method is a URL, not a file path. In your case, the URL will be something like file:///C|/Documents and Settings/Home/Desktop/dropdown.jpg.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.