Download files in firefox browser using selenium WebDriver

FileDownload_FireFox_Selenium

There are situations where we need to

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

We will use browser preferences to [much simpler way]

  • Disable file save dialog
  • set download path

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 FirefoxOptions to set browser preferences

Code implementation

 

For older versions of selenium, follow here

We will be using FirefoxProfile class to set certain preferences and download file from mozilla browser to our local hard disk.

Refer setPreferences for firefoxProfile.

Code implementation –

 

For MIME type or media type, please refer below links –

MIME on wiki

Structured MIME types

Make sure MIME type should match to the file type we are downloading from browser.

 

If you want to download files on Chrome browser, then refer here

For demo, watch here

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!

1 Response

  1. Manjanna K N says:

    Thank you so much.

    This script is worked for me.

Leave a Reply

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