Home > Back-end >  Selenium Firefox Python: How to change download directory
Selenium Firefox Python: How to change download directory

Time:09-09

Hello :/ I am currently having trouble setting up the Download folder inside my project.

I'm using Mac, Pycharm CE, Selenium, Python, Behave, and Firefox (project requirements).

I tried this configuration Python Selenium Firefox trouble with download directory but I'm not sure which part did I do wrong. :/ The downloaded files still go to the default Downloads folder.

from selenium import webdriver
from selenium.webdriver.firefox.options import Options

@given("First step")
def step_impl(context):
    download_path = "/Users/this/is/the/absolute/path/downloads"
    options = Options()
    options.set_preference("browser.download.folderList", '2')
    options.set_preference("browser.download.manager.showWhenStarting", False)
    options.set_preference("browser.download.dir", download_path)
    options.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/csv")
    context.driver = webdriver.Firefox(options=options)

CodePudding user response:

From how to switch download directory using selenium / firefox / python? and Downloading file to specified location with Selenium and python

I suggest try changing

options.set_preference("browser.download.dir", download_path)
options.set_preference("browser.download.dir", '/Users/this/is/the/absolute/path/downloads')

if there are any spaces in the path then try

options.set_preference("browser.download.dir", r'/Users/this/is/the\ space/absolute/path/downloads')
  • Related