I am using a remote selenium webdriver to perform some tests. At some point, however, I need to download a file and check its contents.
I am using the
@FlorentB's answer for Chrome works up until Chrome version 79. For newer versions, the function get_downloaded_files needed to be updated as the downloads.Manager is not accessible anymore. However, this updated version should work with previous versions as well.
def get_downloaded_files(driver):
if not driver.current_url.startswith("chrome://downloads"):
driver.get("chrome://downloads/")
return driver.execute_script( \
"return document.querySelector('downloads-manager') "
" .shadowRoot.querySelector('#downloadsList') "
" .items.filter(e => e.state === 'COMPLETE') "
" .map(e => e.filePath || e.file_path || e.fileUrl || e.file_url); ")