Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in DevOps and Agile by (19.4k points)

I'm using python-selenium and Chrome 59 and trying to automate a simple download sequence. When I launch the browser normally, the download works, but when I do so in headless mode, the download doesn't work.

# Headless implementation

from selenium import webdriver

chromeOptions = webdriver.ChromeOptions()


driver = webdriver.Chrome(chrome_options=chromeOptions)



# ^^^ Download doesn't start

# Normal Mode

from selenium import webdriver

driver = webdriver.Chrome()



# ^^^ Download works normally

I've even tried adding a default path:

prefs = {"download.default_directory" : "/Users/Chetan/Desktop/"}



Adding a default path works in the normal implementation, but the same problem persists in the headless version.

How do I get the download to start in headless mode?

1 Answer

0 votes
by (27.5k points)

This feature of Chrome prevents from software to download files to your computer. In order to enable it via DevTools do this: 

async function setDownload () {

  const client = await CDP({tab: 'ws://localhost:9222/devtools/browser'});

  const info =  await client.send('Browser.setDownloadBehavior', {behavior : "allow", downloadPath: "/tmp/"});

  await client.close();


If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s Selenium training! 

Browse Categories