i want to auto download files and save them in directory, everything is done but firefox stills save files in User download folder eg C:\\users\\root\\Downloads
the function in class PyWebBot
@staticmethod
def FirefoxProfile(path, handlers):
from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.set_preference("browser.download.folderList",1)
profile.set_preference("browser.download.manager.showWhenStarting",False)
profile.set_preference("browser.download.dir", path)
profile.set_preference("browser.download.downloadDir", path)
profile.set_preference("browser.download.defaultFolder", path)
profile.set_preference("browser.helperApps.alwaysAsk.force", False)
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", handlers)
profile.set_preference("pdfjs.disabled", True)
profile.update_preferences()
return profile
then
def setUp(self):
self.profile = PyWebBot.FirefoxProfile(config['downloads'], config['handlers'])
self.driver = webdriver.Firefox(self.profile)
...
...
config:
config['downloads'] = 'Q:/web2py_src/web2py/applications/internet2letter/private/testing/selenium/downloads'
config['handlers'] = 'application/pdf'
There are couple methods to a solution for this problem,
os.path.exists
or os.isfile
Firefox
launches with the selenium driver, navigate to about:config
and check the look up browser.download.dir
, to make sure there was a change. profile.set_preference
( profile.set_preference("browser.download.folderList",2
) has 2
as a second argument, since 0
means to download to the desktop, 1
means to download to the default "Downloads" directory, 2
means to use the directory you specify in "browser.download.dir"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.