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 ...like "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]
  • Can u Just post what kind of error message you are getting ..
    – selva
    Commented Feb 7, 2013 at 12:56

2 Answers 2


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");
  • 1
    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
    Commented Feb 7, 2013 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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