Robot Framework - Download File

Hey,

I’m looking for some advice regarding downloading files from a website and saving them in a defined folder. I need to download a file by clicking a button on a website and then save the file in a folder that I’ve created inside my project.

I know I could use Browser library for it, but I found some issues because all my project (Login and all other tests) is using Selenium Library.

So, I’m trying to do this download through Selenium Library, but I’m facing two main problems:

  • All suggestions I found were using the URL for the download page, but I only have access to the selector that does the download automatically when I click it
  • The name of the file changes every time I download it, so I need an alternative to check dynamically if the file is downloaded in the folder.

I’m testing this in Windows using Chrome.

Hi,

I think the topic below could help you about downloading, as you can set the default download directory in the chrome options used when launching the browser.

I’m usually dealing with same issues, i.e. I have a button to download, print, export or else and get the files downloaded automatically in the folder named dynamically after date-time\test_type\${TEST_NAME}.

In my case names contain the date-time, so it’s quite obvious to find which one is the right candidate with custom scripts. So not knowing how your file naming is, you could use some of these keywords to narrow down which file is interesting for you:

  File Should Exist    path
  Wait Until Created    path
  Should Exist   path
  List Files In Directory
  Get Modified Time

Note that for some of these keyword you can use partial name content with *
I would also suggest that from run to run, download folder should be emptied if results are PASS and you don’t need further analysis, or use Move Files keyword to store previous results for example.

Regards.
Charlie

1 Like

If only part of the name changes, than I would make a keyword, that checks if the file exists based on the fixed part of the name. Using a Glob pattern with the “File Should Exist” keyword in a loop with a sleep, so that you wait a certain amount of time, for the file that should be downloaded.
Also I would delete the file, if you don’t need it anymore, once it’s downloaded.

Skip the above part about the loop. The “Wait Until Created” keyword is in this case much more convenient :grin:.

1 Like