title: Downloading images using selenium webdriver
body: <p>I'm trying to download images from a website like so:</p>
  
  <pre><code>        List &lt;WebElement&gt; listofItems = driver.findElements(By.cssSelector("div.heroThumbnails:nth-child(4) &gt; div:nth-child(2) &gt; div:nth-child(n)"));
      URL imageURL = null;
      for(WebElement myElement : listofItems) {
          String j = myElement.getAttribute("data-bigurl");
          System.out.println(j);
          for(int i = 0; i &lt; listofItems.size(); i++){
              try {
                  //generate url
                  imageURL = new URL(j);
                  int countF = 0;
                  //read url and retrieve image
                  BufferedImage saveImage = ImageIO.read(imageURL);
  
                  //download image to the workspace where the project is, save picture as picture.png (can be changed)
                  ImageIO.write(saveImage, "jpg", new File(countF++ + ".jpg"));
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
      }
  </code></pre>
  
  <p>When the picture is saved, it is overwriting the previous one. How can I fix this? Any help would be appreciated, thanks.</p>