0

This is about the ChromeDriver for Selenium. So I know I can set the default directory by passing arguments to the Driver constructor like so:

chromeOptions = webdriver.ChromeOptions()
prefs = {"download.default_directory" : "/path/to/directory/"}
chromeOptions.add_experimental_option("prefs",prefs)
driver=Chrome(chrome_options=chromeOptions)

But I want to change that directory after a criteria has been met. Say after 15 files have been downloaded, I need to change my download location to "/path/to/new_directory/". Haven't really been able to find a simple solution to this.

Alternatively, I am also happy if I can simply rename files after my criteria has been met (the criteria is not as simple as every 15th file but you get the idea) but somehow that sounds like it would be trickier because Selenium has no access to the downloads once they start.

NarendraR
  • 7,577
  • 10
  • 44
  • 82
doddy
  • 579
  • 5
  • 18
  • 1
    Check [this ticket](https://stackoverflow.com/questions/34548041/selenium-give-file-name-when-downloading). You can rename last downloaded file or move it to new folder – Andersson Sep 10 '18 at 20:14
  • You would need to recreate the driver after you change the default download path. This seems overly complicated... what are you trying to do? Why do you need to change the download path? – JeffC Sep 10 '18 at 20:40
  • Just downloading a lot of files but they need to be under their own specific folders. For example, test_case_1 might have 10 files that need to be under test_case_1 and test_case_2 might have 3 files that need to be saved under test_case_2 etc. – doddy Sep 11 '18 at 14:28

0 Answers0