I am testing an AngularJS site using Selenium.
A test involves downloading a file from the site.
My original plan was to download the file directly using Selenium (by clicking on the export button via Selenium and then waiting for the file to download using Wait for finished download file in selenium and c# — this answer or similar). However, this is explicitly discouraged by Selenium (https://selenium.dev/documentation/en/worst_practices/file_downloads/).
Inspecting the export button reveals that it calls a function named export:
<button type="button" class="btn btn-warning" ng-click="export()">{{'export' | translate}}</button>
By observation, it appears that the export button creates a file server-side with a fresh GUID and then starts a download using that file.
My new plan is to obtain the download link and then download it using How to download a file from a website in C# — this answer or similar. However, the link to the file is only valid if you are logged in, so I would also need to simulate that somehow.
Authentication is performed by requiring an OAuth bearer token on each request.
How can I find the download link of a file (given that it is obscured by a function) and then download it (given that access to file is restricted to logged-in users)?