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

后端 未结 9 1181

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 18:57

    To obtain the return of more than one item, I had to change the answer of @thdox 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("""
            var elements = document.querySelector('downloads-manager')
            .shadowRoot.querySelector('#downloadsList')
            .items
            if (elements.every(e => e.state === 'COMPLETE'))
            return elements.map(e => e.filePath || e.file_path || e.fileUrl || e.file_url);
            """)
    

提交回复
热议问题