Skip to content
Software Testing Journal
Software Testing Journal

Your daily dose of learning!

  • Blog
  • Help Center
  • Video Playlist
  • Podcast & FAQ
  • Privacy Policy
Software Testing Journal

Your daily dose of learning!

Selenium Logo

Restriction download option in Selenium

Dheeraj Gambhir, 2023-11-202023-11-20

At times, we need to visit a page in our application that automatically starts downloading the file which is as per the feature of that page. But we’re navigating to this page (A) only to further navigate to the other page (B) by clicking on some link given on this page (A) which redirects us to page (B) but at the same time, we don’t want to download the file on visiting this page (A) as it’s not required every time while running our Selenium automation script.

Did you know there is a preference option “download_restrictions” that can help us achieve this?

Let’s say A is this: http://selenium-release.storage.googleapis.com/2.41/selenium-java-2.41.0.zip

HashMap<String, Object> prefs = new HashMap<String, Object>();

prefs.put(“download_restrictions”, 3);

ChromeOptions opt = new ChromeOptions();

opt.setExperimentalOption(“prefs”, prefs);

WebDriverManager.chromedriver().setup();

driver = new ChromeDriver(opt);

driver.get(“http://selenium-release.storage.googleapis.com/2.41/selenium-java-2.41.0.zip“);

Note* You can specify the type of downloads that Google Chrome will block, depending on how secure they are: https://support.google.com/chrome/a/answer/7579271?hl=en

If you find this post helpful, please share them with your colleagues and friends.

  • Facebook
  • Twitter
  • LinkedIn
  • Email
Automation DownloadSeleniumTips

Post navigation

Previous post
Next post
©2025 Software Testing Journal | WordPress Theme by SuperbThemes