You need to avoid clicking on the download file by optimizing the download operation properly, save it to disc after opening downloads. Selenium can be useful here to perform all the operations by using browser profiles with the required configurations.
You can find all the changes you need to make with Firefox and on Safari on Mac. I hope this will help you.
If you want to become an expert in Selenium, check out this Selenium Certification offered by Intellipaat.