How to change download directory location path in Selenium using Chrome?

2024/12/9 22:03:33

I'm using Selenium in Python and I'm trying to change the download path. But either this:

prefs = {"download.default_directory": "C:\\Users\\personal\\Downloads\\exports"}
options.add_experimental_option("prefs", prefs)`

or this

options.add_argument("--download.default_directory --C:\\Users\\personal\\Downloads\exports")`

are not working.

In first case I also get the error

from invalid argument: unrecognized chrome option: prefs

Can someone help?

Answer
options = webdriver.ChromeOptions()
options.add_argument("--headless")
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
options.add_experimental_option('excludeSwitches', ['enable-logging'])
prefs = {"profile.default_content_settings.popups": 0,    "download.default_directory":r"C:\Users\xxxx\xxxx\ccc\xxxx\xx\xx", ### Set the path accordingly"download.prompt_for_download": False, ## change the downpath accordingly"download.directory_upgrade": True}
options.add_experimental_option("prefs", prefs)
driver = Chrome(service=Service(PATH), options=options)
https://en.xdnf.cn/q/72930.html

Related Q&A

Keras, TensorFlow : TypeError: Cannot interpret feed_dict key as Tensor

I am trying to use keras fune-tuning to develop image classify applications. I deployed that application to a web server and the image classification is succeeded.However, when the application is used …

How to get matplotlib to place lines accurately?

By default, matplotlib plot can place lines very inaccurately.For example, see the placement of the left endpoint in the attached plot. Theres at least a whole pixel of air that shouldnt be there. In f…

Using Flask as pass through proxy for file upload?

Its for app engines blobstore since its upload interface generates a temporary endpoint every time. Id like to take the comlexity out of frontend, Flask would take the post request and forward it to th…

What does printing an empty line do?

I know this question may well be the silliest question youve heard today, but to me it is a big question at this stage of my programming learning.Why is the second empty line needed in this Python code…

Django - how do I _not_ dispatch a signal?

I wrote some smart generic counters and managers for my models (to avoid select count queries etc.). Therefore I got some heavy logic going on for post_save. I would like to prevent handling the signa…

Python 3 Decoding Strings

I understand that this is likely a repeat question, but Im having trouble finding a solution.In short I have a string Id like to decode:raw = "\x94my quote\x94" string = decode(raw)expected f…

how get context react using django

i need get context in react using django but i cant do itthis is my code in my jsx <h1>{{titulo}}</h1> <h2>{{ejemplo}}</h2>in my template:{% load staticfiles %} <!DOCTYPE ht…

Copy certain files from one folder to another using python

I am trying to copy only certain files from one folder to another. The filenames are in a attribute table of a shapefile. I am successful upto writing the filenames into a .csv file and list the column…

I want to create django popup form in my project [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 5…

SVG to PNG with custom fonts in Python

Im using Cairo/RSVG based solution for rasterizing SVG to PNG. Its already beeb described on StackOverflow in Convert SVG to PNG in Python. However, this solution doesnt seem to work with custom fonts.…