Ich möchte Dateien automatisch herunterladen und im Verzeichnis speichern, alles ist erledigt, aber firefox stills speichert Dateien im Benutzerdownload-Ordner, z. C:\users\root\Downloads
selen setzt downloaddir nicht in FirefoxProfile
die Funktion in der Klasse 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
dann
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'
Versuchen Sie es mit' '\\ statt'/'. Ich hatte dieses Problem vor einiger Zeit. – enginefree
hat nicht funktioniert :(Ich werde versuchen, os.path.join –
zu verwenden Sind Sie sicher, dass es existiert? Es wird am besten sein, in Ihrem Skript sicherzustellen, etwas wie 'if os.path.exists' oder' os.isfile ' – enginefree