Skip to content Skip to sidebar Skip to footer

What Is Wrong With This Selenium Firefox Profile To Download File Into Customized Folder?

I am using selenium and python v3.6 to automate firefox to download file into a customized folder. The location of the folder is C:/Users/username/Dropbox/Inv/. Below is my firefox

Solution 1:

You need to use profile while launching Firefox:

driver = webdriver.Firefox(firefox_profile = profile)

Check 8.4. How to auto save files using custom Firefox profile ? in Selenium Docs FAQ.

This is the example in the link:

import os

from selenium import webdriver

fp = webdriver.FirefoxProfile()

fp.set_preference("browser.download.folderList",2)
fp.set_preference("browser.download.manager.showWhenStarting",False)
fp.set_preference("browser.download.dir", os.getcwd())
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream")

browser = webdriver.Firefox(firefox_profile=fp)
browser.get("http://pypi.python.org/pypi/selenium")
browser.find_element_by_partial_link_text("selenium-2").click()

Solution 2:

I will answer my own question. The problem lies with the string specifying the download directory. I should use \\ and not /.

profile.set_preference('browser.download.dir', 'C:\\Users\\username\\Dropbox\\Inv')

The code has been verified to be working now.

Post a Comment for "What Is Wrong With This Selenium Firefox Profile To Download File Into Customized Folder?"