How to download a file in headless mode?

Hi, I have an Open Browser activity that goes on a site, makes two clicks in order to save the file, 10 secounds delay and then closes the tab. The clicks are set to SimulateClick=True. Everything works just fine with both Native or WebDriver method.
But I need to start the browser in Headless mode (Hidden=True in Open Browser activity) because I’m making a background automation that saves the said file. Now, in Headless mode the browser is not saving the file, it doesn’t matter which browser (edge, chrome, firefox) I’ve tried all of them, same issue. And I don’t get any error. No WebDriver error. No click activity error. Nothing
I can’t use IE because the site doesn’t support IE anymore.
Any thoughts on how to make the browser download the file in Headless mode?

can you instead get the URL of the download? If so, you can use web activities to download the file. Instead of a click activity you can use ‘get attribute’ on the hyperlink to extract the URL


I think I could but in order to get the URL I would have to go through 4-5 Invoke Code activities that make API requests + for each file that gets downloaded the identifier has to be unique when the said API requests are made so I think I would need to add some Regex stuff in order to get the URL.
It just seems as too much work for something that can be achieved with two clicks IMO

why would you need to go through all that? As stated previously, you can use the ‘get attribute’ activity instead of a ‘click’ activity to get the URL. No need for regex or anything like that. Just replace the click activity with get attribute, then supply the extracted URL to the ‘http request’ activity and specify where you’d like it to be saved (including file extension) in the ‘output file’ section of the http request activity.

It should be slightly faster than doing it via click as it doesn’t require webpages to fully render and can all be done in the background. I’ve done hundreds of different bots using this method as it’s my preferred method for downloading files on the web

1 Like

I can’t get the URL using ‘get attribute’. Maybe because after I press the said button (download file type, as in: Combined, Single View PDF) appears a window that says “Please wait” and the downloading begins. So that button just triggers the downloading event I guess.
I’m trying to download a PDF from Draftable if someone heard about it.

Dont click the button. Navigate to that download file button and use the ‘get attribute’ activity instead (you can use the same selectors you used for the click activity). Choose the HREF attribute and save the output to a string variable. Next use the ‘http request’ activity (found in uipath web activities library).

NOTE: if you have to sign in to download the file, then the http request activity may not work to download the file.

I’ve managed to do it using their API. Would’ve been easier with the clicks but it works just fine with all of the invoke codes and requests that I had to put into it (I’ve used RestSharp instead of HTTP Request because the HTTP Request wasn’t working properly with their API). Thank you for your help, Dave.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.