Download Restrictions in Chrome using Selenium
Feb 26, 2023
Problem Statement:
Is it possible to disable file download in chrome using selenium
By Setting this policy the users can’t bypass the download security and to achieve the same using Selenium, we can set the “download_restrictions” preference as mentioned below:
How to do it in your Automation Using Selenium:
Code:
ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<>();
prefs.put("download_restrictions", 3);
options.setExperimentalOption("prefs", prefs);
WebDriver driver = new ChromeDriver(options);
Please find the below code and their meaning for download Restrictions within Chrome:
- 0 = No special restrictions.
- 1 = Block malicious downloads and dangerous file types.
- 2 = Block malicious downloads, uncommon or unwanted downloads and dangerous file types.
- 3 = Block all downloads.
- 4 = Block malicious downloads.
#Ref: https://chromeenterprise.google/policies/#DownloadRestrictions
Supported Version:
- Version ≥ 61.