This code will iterate through a number of pages to find and extract elements on the page. Once the loop has completed it will generate a log file with these elements from a HashMap, but the results aren't being appended and are rather being overwritten.
        int d = new Integer(0);
        for (int i = 0; i <= 100; d += 10) {
            String url = Constants.FilterUrl + "&startIndex=" + d;
            this.getAuthors();
            driver.get(url);
            if (!driver.getPageSource().contains("h3")) break;
            }   
        /* Send HashMap values to text file */
        File file = new File(Constants.FILEPATH + Constants.dateFormat.format(new Date()) + ".txt");
        try{
            if(!file.exists()){
                System.out.println("We had to make a new file.");
                file.createNewFile();
            }
                PrintWriter out = new PrintWriter(new FileWriter(file), true);
                map.forEach((k, v) -> out.println(k + ", " + v));
                out.append("************** " + "\n");
                out.close(); 
            } catch(IOException e) {
                System.out.println("COULD NOT LOG!!");
            }
}
public void getAuthors(){
    List<WebElement> allElements = driver.findElements(By.tagName("h3"));
    /* Create HashMap and store H3 elements in the key set */
    this.map = new HashMap<String, String>();
    for (WebElement element1 : allElements) {
        map.put(element1.getText(), element1.findElement(By.tagName("a")).getAttribute("href"));
    }
    /* Visit pages for H3 elements and retrieve names of the authors */
    for (Map.Entry<String, String> entry : map.entrySet()) {
        driver.get(entry.getValue());
        entry.setValue(driver.findElement(By.className("userlink-0")).getText());
    }
}
Any ideas?
 
     
     
    