Download files in Chrome browser using selenium WebDriver

There are situations where we need to

  • Download files from browser,
  • Save in a specified folder on hard disk.

Update – If you are using latest version of selenium like 3.10 onwards – ChromeDriver(cap) is deprecated, need to use only ChromeOptions

We will use ChromeOptions to set browser preferences [much simpler way]

  • Disable file save dialog
  • set download path

File will be downloaded under sel folder.

For older versions of selenium, follow here

We will be taking help of ChromePreferences, ChromeOptions and DesiredCapabilities of Chrome in selenium.




Find below code to download files in Chrome browser:

Find the downloaded file under the specified folder – c:\download

Content posted is based on learning or working experience, Share the post with others if find useful, Any queries?, leave comments or discuss on our facebook:qavalidation.com, Thanks!

6 Responses

  1. Hussain says:

    By using Robot class, we can achieve this easily…

    if Save Button is Highlighting in Download popup:
    Robot r=new Robot();
    r.keyPress(KeyEvent.VK_ENTER);
    r.keyRelease(KeyEvent.VK_ENTER);

  2. NAMBIAR says:

    Hello, I tried exactly the same solution and it’s showing me the Save window. Then I sued the Robot key event and it’s downloading to the user default download folder and NOT to the custom download directory.

  3. Ed B says:

    Line 17 is empty because line 11 is instantiated but never assigned.

  4. Anonymous says:

    Chrome doesnot launch save window….mozilla does…this code is for chrome and not mozilla……mozilla has diff code……I tried this and this is working absolutely fine for me…..i opened my folder that i gave path for downloading……..it downloaded in that particular folder itself

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: