Chrome headless file download from Selenium in Python

In silent mode, Chrome prohibits the download of files by default.

However, they recently added the DevTools parameter to enable this behavior:

https://chromedevtools.imtqy.com/devtools-protocol/tot/Page/#method-setDownloadBehavior

Using Selenium with ChromeDriver in Python, how to allow file downloads?

+4
source share
2 answers

For those who are still watching, Here's how I did it:

def enable_download_in_headless_chrome( driver, download_dir):
    #add missing support for chrome "send_command"  to selenium webdriver
    driver.command_executor._commands["send_command"] = ("POST", '/session/$sessionId/chromium/send_command')

    params = {'cmd': 'Page.setDownloadBehavior', 'params': {'behavior': 'allow', 'downloadPath': download_dir}}
    driver.execute("send_command", params)
+2
source

, : https://bugs.chromium.org/p/chromedriver/issues/detail?id=1973

Chrome (# 60). # 62, Dev. , ChromeDriver .

https://bugs.chromium.org/p/chromium/issues/detail?id=696481, :

Chrome: Chromium 58.0.3023.0

? (1) (--headless) (2) URL- (3)

?

URL , "", .

?

, .

-1

Source: https://habr.com/ru/post/1685372/


All Articles