Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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();
        rcc.setPort(3333);
        SeleniumServer ss = new SeleniumServer(rcc);
        ss.start();



DefaultSelenium  browser = new DefaultSelenium("localhost" , 3333 , "*firefox" ,"http://");
        browser.start();
        browser.open("http://sqa.stackexchange.com/questions/ask");
        browser.windowMaximize();
        browser.setSpeed("20000");
        browser.click("id=nav-askquestion");
        browser.click("id=wmd-image-button");

//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

2 Answers 2

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

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
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 Feb 7 '13 at 19:29

Your Answer

 
discard

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.