title: Wait for Download to finish in selenium webdriver JAVA
body: <p>Once clicking a download button, files will be downloaded. Before executing next code, it needs to wait until the download completes.</p>
  
  <p>My code looks like this:</p>
  
  <pre><code>Thread.sleep(2000);
  driver.findElement(By.xpath("//*[@id='perform']")).click();//click for download
  
  Thread.sleep(20000);
  //code to be executed after download completes
  Readfile fileobj=new Readfile();
  String checkfile=fileobj.checkfilename();
  </code></pre>
  
  <p>How can I make the webdriver wait until a download completes?</p>