title: naming a file when downloading with Selenium Webdriver
body: <p>I see that you can set where to download a file to through Webdriver, as follows:</p>
  
  <pre><code>fp = webdriver.FirefoxProfile()
  
  fp.set_preference("browser.download.folderList",2)
  fp.set_preference("browser.download.manager.showWhenStarting",False)
  fp.set_preference("browser.download.dir",getcwd())
  fp.set_preference("browser.helperApps.neverAsk.saveToDisk","text/csv")
  
  browser = webdriver.Firefox(firefox_profile=fp)
  </code></pre>
  
  <p>But, I was wondering if there is a similar way to give the file a name when it is downloaded? Preferably, probably not something that is associated with the profile, as I will be downloading ~6000 files through one browser instance, and do not want to have to reinitiate the driver for each download.</p>
  
  <hr>
  
  <p>Edit: Solution with code as suggested by the selected answer. Rename the file after each one is downloaded.</p>
  
  <pre><code>import os
  os.chdir(SAVE_TO_DIRECTORY)
  files = filter(os.path.isfile, os.listdir(SAVE_TO_DIRECTORY))
  files = [os.path.join(SAVE_TO_DIRECTORY, f) for f in files] # add path to each file
  files.sort(key=lambda x: os.path.getmtime(x))
  newest_file = files[-1]
  os.rename(newest_file, docName+".pdf")
  </code></pre>