title: Make Selenium wait for a file download to finish
body: <p>I managed to download the file silently with Selenium. But Firefox automatically renames the file by adding 1,2,3.. to file names as each file sent by the server has the same name. But I want to rename the files based on current date &amp; time. So, tried:</p>
  
  <ol>
  <li><p>Start downloading the file-> downloadLink.click();</p></li>
  <li><p>While( NOT file-With-original-name exists OR &lt;filename&gt;.part exists)
      &nbsp;&nbsp;&nbsp;{ <code>Thread.sleep(2000);</code> }<br></p></li>
  <li><p>Rename the downloaded file to desired name.</p></li>
  </ol>
  
  <p>But it renames some files. And some are 0 length and the last file is not even renamed. I think this is because my code continues after download and doesn't poll in the while loop. What should I do ? Thanks in advance.</p>