I am using ‘selenium-webdriver’ npm package to simulate an endpoint user – I click on buttons, select drop-downs and checkboxes.
I come across an image that will help me download a PDF file.
- So what I want and what happens when I manually click on this image button on a regular chrome tab is that it will prompt a save-window:
- What actually happens is that the file is downloaded automatically in the default directory (which is ‘download’ folder for me), without showing the save-window prompt. If the same file is already present in the download folder, then the new file gets a suffix of “(2)” or a corresponding number to its name.
I generally use this basic Selenium documentation: https://www.selenium.dev/documentation/en/getting_started_with_webdriver/browsers/
2nd reference I use is: Selenium-javascript-docs
Most of the Selenium question-answers are in the java language, so those don’t help me as I’m using the javascript package.
I do know it has to do with the chrome options, or a chrome-specific field, but the document is just lacking. I came across the chrome-driver doc, but it is not javascript-friendly.
Other than disabling the automatic-download feature, I am also interested in changing the download directory to a custom location.
Any help or reference/guide/documentation source is greatly appreciated. Thank you in advance and thank you for reading.
Advertisement
Answer
You can use setDownloadPath to modify the path where the file will be downloaded.
Other than that, I don’t think there’s an option to prevent the automatic download