Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use chrome webdriver in selenium to download files in python?

Tags:

Based on the posts here and here I am trying to use a chrome webdriver in selenium to be able to download a file. Here is the code so far

from selenium import webdriver from selenium.webdriver.chrome.options import Options  chrome_options = Options() chrome_options.add_argument("--disable-extensions") chrome_options.add_experimental_option("profile.default_content_settings.popups", 0) chrome_options.add_experimental_option("download.prompt_for_download", "false") chrome_options.add_experimental_option("download.default_directory", "/tmp")  driver = webdriver.Chrome(chrome_options=chrome_options) 

But this alone results in the following error:

WebDriverException: Message: unknown error: cannot parse capability: chromeOptions from unknown error: unrecognized chrome option: download.default_directory   (Driver info: chromedriver=2.24.417424 (c5c5ea873213ee72e3d0929b47482681555340c3),platform=Linux 4.10.0-37-generic x86_64) 

So how to fix this? Do I have to use this 'capability' thing? If so, how exactly?

like image 907
Alex Avatar asked Oct 25 '17 16:10

Alex


1 Answers

Try this. Executed on windows

(How to control the download of files with Selenium Python bindings in Chrome)

from selenium import webdriver from selenium.webdriver.chrome.options import Options  options = Options() options.add_experimental_option("prefs", {   "download.default_directory": r"C:\Users\xxx\downloads\Test",   "download.prompt_for_download": False,   "download.directory_upgrade": True,   "safebrowsing.enabled": True }) 
like image 190
Satish Avatar answered Sep 18 '22 13:09

Satish