Selenium is encountering an issue where it is unable to automatically download files, as the download confirmation

While reviewing someone else's code, I encountered an issue with automatically downloading PDF files from a web page using selenium.

Despite setting the browser.helperApps.neverAsk.saveToDisk property to the PDF mime type, I am still getting the firefox download confirmation prompt.

I have tried downgrading my Firefox version from 70 to 60.0 but that did not solve the problem. It is unclear whether this is a code issue or a compatibility problem between Selenium and Firefox.

I would greatly appreciate any assistance.

edit: Here is what the download confirmation pop up looks like.


private static final String mimeTypeToSaveToDisk = "application/pdf;application/zip";

public void download(String url, String downloadDirPath) {          
    // Code for downloading
}

Answer №1

After reviewing your use of FirefoxOptions, I have a suggestion for you to try out - the useDownloadDir option. Although you are already utilizing browser.download.dir, this new setting may offer a different approach:

FirefoxOptions options = new FirefoxOptions();
options.setPreference("browser.download.folderList", 2);
options.setPreference("browser.download.dir", "C:\\Windows\\temp");
options.setPreference("browser.download.useDownloadDir", true);
options.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf");
options.setPreference("pdfjs.disabled", true);  // prevent PDF from opening after download

WebDriver driver = new FirefoxDriver(options);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Guide on Implementing jQuery Plugin with Vue, Webpack, and Typescript

I am currently exploring the integration of the jQuery Plugin Chosen into my vue.js/Webpack project with TypeScript. After some research, I discovered that it is recommended to encapsulate the plugin within a custom Vue component. To kick things off, I m ...

Angular: promptly exit out of ngClick event handler

I have a selection menu on my webpage that is essentially an unordered list, with each item in the menu formatted like this: <li ng-click='doCalc(5)'>Five</li> The doCalc function that is triggered by clicking on these items may tak ...

Discover a method to retrieve all recommended strings based on a search query using JavaScript

I have two strings: one containing all the values of countries and the second string that I entered when searching for a country. Now, I am looking to retrieve all results that contain "In", such as India and Indonesia. For example, if I search for "IN" ...

Tips for avoiding crashes in my Selenium/Python application

I recently developed a program that fetches a single record from Google Sheet, processes it, deletes it, and continues this loop. However, whenever I update the Google Sheet, the program deducts a record in the next cycle, processes it, and then deletes it ...

I have been attempting to implement validation in JQuery, but it doesn't seem to be functioning correctly

Can someone assist me with adding validation in jQuery? I'm stuck and need help solving this problem. $(function(){ $("#btn").click(function(){ var b=prompt("Enter your link"); $("a").attr("href",b); if($("b").v ...

Data from AngularFire not displaying in my list application

While going through tutorials on the Angular website, I encountered a roadblock while attempting to create a list that utilizes Firebase for data storage. Strangely, everything seems to be functional on the Angular site, but clicking on the "Edit Me" link ...

Issues arise when trying to use the Jquery append() method in conjunction with Angular

We are currently utilizing jquery version 1.9.1 and angular version 1.2.13 for our project. Our wysiwyg editor is functioning well, as we are able to save HTML into the database and load it back using the jquery append function successfully. However, we ar ...

Having trouble fixing the '@material-ui/lab' error while working with the newest React update?

My goal is to set up a global alert by following this method: Check out the Sandbox Demo Yet, I encounter an issue with the following error message: ERROR in ./src/components/snackbar/Alert.js 5:0-82 Module not found: Error: Can't resolve '@m ...

Ways to Determine the Height and Width of an Image Once it has been Adjusted for a View

Is there a way to retrieve the height and width of an image after it has been resized for a view? I have images that may vary in original dimensions, but users can resize them as needed. For example, this code from the console gives the client height: do ...

The error message 'Blob is undefined' pops up when trying to use react-media-recorder in an Astro project

I'm currently working on a project that involves Astro and React components, and I'm attempting to integrate react-media-recorder. The code I have is quite simple, just a React component placed within an Astro page: import { useReactMediaRecorde ...

Analyzing past UTC date times results in a peculiar shift in time zones

When I receive various times in UTC from a REST application, I encounter different results. Examples include 2999-01-30T23:00:00.000Z and 1699-12-30T23:00:00.000Z. To display these times on the front end, I use new Date(date) in JavaScript to convert the ...

The voting system will increase or decrease by 1 to 5 during each round

Recently, I added a voting system to my website inspired by this source. It's functioning well, but there is an issue where each vote can sometimes count for more than one. You can view the source code on the original website and test it out live here ...

Verify the existence of an HTML file prior to routing in AngularJS and NodeJS

Currently, I am facing a challenge in my NodeJS project that involves AngularJS for routing management. My issue lies in checking if a selected HTML file exists before routing to it. Despite trying numerous solutions, I have not been able to find one that ...

How can I prevent Heroku from automatically running the script with 'npm start'?

I am currently in the process of developing a server-based application that utilizes automated scripts, also known as "bots," within a cloud environment. I have set up Heroku Scheduler to execute one of these scripts automatically, as illustrated in Figure ...

Updating the Ajax Url dynamically while scrolling

I am trying to update the Ajax URL dynamically, and here is my progress so far: var size=1; var from = 1; window.addEventListener('mousewheel', function(e){ if(e.wheelDelta<0 && from<5){ from++; } else if(e.whe ...

Tips for enabling selection of list items in an input tag

Below is the code I have written to create an InputFilter. MyFilter = function(args) { var dataUrl = args.url; var divID = args.divID; var div = document.getElementById(divID); var myTable = '<input type="text" id="myInput" on ...

Utilizing Regular Expressions in AngularJS to validate name, a 10-digit mobile number, and a 12-digit number through the ng-blur event and match

I am struggling to validate the three inputs mentioned above and having trouble using the right functions. Can someone please assist me with this? Here is the HTML code for the 3 inputs: <input id="name" ng-model="user.name" ng-blur="checkIfNameIsVali ...

Is there a way for me to customize the appearance of the Material UI switch component when it is in the checked

I am seeking to customize the color of the switch component based on its checked and unchecked state. By default, it displays in red. My goal is to have the "ball knob" appear yellow when the switch is checked and grey when it is not. This styling must be ...

Having trouble loading the Google API using getScript. Is displaying a ReferenceError message: "Variable google not found."

I am attempting to dynamically load the Google API using the getScript() method for implementing a "Place Autocomplete Address Form". For more information, you can visit this link: https://developers.google.com/maps/documentation/javascript/examples/places ...

Establishing headers in hapi.js

Seeking guidance on setting up custom variables for individual routes in hapi.js. How can I configure these variables to be accessible on 'onPreHandler'? Additionally, looking for a way to include headers right before calling reply.continue. Any ...