I’m trying to automate a file download process for testing. The webpage uses JavaScript, so simple HTTP clients won’t work. I’ve been using Firefox with Selenium, but it’s not headless. Here’s a snippet of my current setup:
This works, but I need a headless solution. I tried PhantomJS, but it doesn’t support downloads on Linux. Are there any headless browsers that work with Selenium and can handle downloads? I’d love to keep a similar setup if possible. Any suggestions would be super helpful!
I’ve tackled this issue before and found a solution using Chrome in headless mode. It’s been reliable for automating downloads in my testing workflows. Here’s how I set it up:
This configuration has worked well for me on both Linux and Windows. The key is setting the correct preferences for Chrome. You might need to tweak the download directory path based on your system. One caveat: make sure you have the latest chromedriver installed and compatible with your Chrome version. I’ve run into issues when these were out of sync.
While Chrome is a popular choice, I’ve had success using Firefox in headless mode for Selenium-based file downloads. Here’s a configuration that’s worked well for me:
This setup maintains most of your original code while enabling headless mode. Ensure you’re using the latest geckodriver and Firefox versions for compatibility. In my experience, this approach has been reliable across different operating systems and doesn’t require significant changes to existing Firefox-based scripts.