Selenium firefox profile download directory preference not getting implemented

289 Views Asked by At

I have the following code

profile = webdriver.FirefoxProfile()
    profile.set_preference("browser.download.folderList", 2)
    profile.set_preference("browser.download.manager.showWhenStarting", False)
    profile.set_preference("browser.download.dir", os.path.dirname(os.path.realpath(__file__)))
    profile.set_preference("browser.helperApps.neverAsk.openFile", "application/zip")
    driver = webdriver.Firefox(firefox_profile=profile)

But when the zip file gets downloaded it still gets downloaded to my temp dir.

Any help here will be greatly appreciated!

1

There are 1 best solutions below

1
undetected Selenium On

You need to make two minor modifications as follows:

os.path.dirname(os.path.realpath(__file__))

with:

os.path.abspath(os.path.dirname(__file__))

followed by the line:

profile.set_preference("browser.download.folderList", 2)

Effectively, your code block will be:

profile = webdriver.FirefoxProfile()
    profile.set_preference("browser.download.dir", os.path.abspath(os.path.dirname(__file__)))
    profile.set_preference("browser.download.folderList", 2)
    profile.set_preference("browser.download.manager.showWhenStarting", False)
    profile.set_preference("browser.helperApps.neverAsk.openFile", "application/zip")
    driver = webdriver.Firefox(firefox_profile=profile)

References

You can find a detailed discussion on os.path.abspath(os.path.dirname(__file__)) in what does the file variable mean/do?