Selenium (Python) - waiting for a download process to complete using Chrome web driver

后端 未结 9 1164

I\'m using selenium and python via chromewebdriver (windows) in order to automate a task of downloading large amount of files from different pages. My code works, but the so

9条回答
  •  时光取名叫无心
    2020-12-04 19:03

    With Chrome 80, I had to change the answer from @florent-b by the code below:

    def every_downloads_chrome(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);
            """)
    

    I believe this is retro-compatible, I mean this shall be working with older versions of Chrome.

提交回复
热议问题