title: Loop through downloading files using selenium in Python
body: <p>This is a follow-up question to <a href="https://stackoverflow.com/questions/30323081/download-files-using-python-3-4-from-google-patents">this</a> previous question on how to download ~1000 files from Google Patents.</p>
  
  <p>I would like to iterate through a list of filenames <code>fname = ["ipg150106.zip", "ipg150113.zip"]</code> and simulate clicking and saving these files to my computer. The following example works for me and downloads a single file:</p>
  
  <pre><code>from selenium import webdriver 
  from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
  
  # Define parameters
  savepath = 'D:\\' # set the desired path here for the files
  
  
  # Download the files from Google Patents
  profile = FirefoxProfile ()
  profile.set_preference("browser.download.panel.shown", False) 
  
  profile.set_preference("browser.download.folderList", 2) # 2 means specify custom location
  profile.set_preference("browser.download.manager.showWhenStarting", False)
  profile.set_preference("browser.download.dir", savepath) # choose folder to download to
  profile.set_preference("browser.helperApps.neverAsk.saveToDisk",'application/octet-stream')
  
  driver = webdriver.Firefox(firefox_profile=profile)
  
  url = 'https://www.google.com/googlebooks/uspto-patents-grants-text.html#2015'
  driver.get(url)
  
  filename = driver.find_element_by_xpath('//a[contains(text(), "ipg150106.zip")]')
  filename.click()
  </code></pre>
  
  <p>I've tried to replace this with a list and a loop like this:</p>
  
  <pre><code>fname = ["ipg150106.zip", "ipg150113.zip"]
  
  for f in fname:
      filename = driver.find_element_by_xpath('//a[contains(text(), f)]')
      filename.click()
      print('Finished loop for: {}.'.format(f))
  </code></pre>
  
  <p><strong>However, the browser opens, but nothing happens (no clicking on files). Any ideas?</strong></p>