Using Selenium webdriver with chrome browser for automation - Junit or java programming - how to upload a file from desktop(or any folder in pc) to application


1 Answer 1


A sample program for it:

public class FileUpload {

    public static void main (String args[])
        WebDriver driver = new FirefoxDriver();

        driver.findElement(By.xpath("//input[@title='Upload file']")).click();

  • Hi, Sathis D, perhaps you could make your answer more useful by adding some explanation of your code. As it stands, an experienced coder would have no issues working out what to replace (such as using a Chrome driver rather than Firefox, since the OP specifically mentioned Chrome)
    – Kate Paulk
    Jan 30, 2014 at 12:07
  • I already did that, it did not work. For that to work the upload field should also accept url or path. The button I am working with is not accepting url or path only can click and it opens finder, from there should select desired file. Using Selenium I am unable to type path in Finder also after opening. I asked our Javascript dev to change that button to support path/url button he could not to do it. So, I used sikuli .. as sikuli is not reliable, I used Auto IT but when running as a batch its problematic.
    – user6859
    Feb 6, 2014 at 19:08

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