0

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!

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Nov 10 '21 at 17:06

1 Answers1

0

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?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • It's still downloading into the temp dir, I made a way around this by just moving the file out of temp but that's not a solid work around as the file it is downloading could change names – JFCCoding Nov 10 '21 at 19:48