How to check if file got downloaded from browser using selenium2library

Auto-learner picture Auto-learner · May 26, 2016 · Viewed 11.9k times · Source

Can someone help me How to check if file got downloaded from browser using selenium2library,RobotFramework.In my current test I am able to click the download button and file is getting downloaded but what happens if the file didn't get downloaded eventhough button is clicked. Any sample code is helpful.

Answer

TiagoLr picture TiagoLr · May 19, 2017

In chrome I open the chrome://downloads page and then retrieve the downloaded files list from shadow DOM like this:

const docs = document
  .querySelector('downloads-manager')
  .shadowRoot.querySelector('#downloads-list')
  .getElementsByTagName('downloads-item');

This solution is restrained to chrome, the data also contains information like file path and download date.