title: Using HtmlUnit to click on multiple images on same page that have same source attribute but different onclick events
body: <p>I'm using HtmlUnit to get data from a webpage. The web page has multiple images that look the same and have the same src value but each one has a different onclick event that directs it to a new page depending on which image was clicked and it is this new page that I need to save the data from. I need to loop through the images and click each one to get the results of the onclick event. At the moment the code I have loops through the images but each file contains the output from the onclick of the first image.
  Can someone point out where I am missing something please? My code is as follows:
  customer in the file name is a variable that I have declared earlier in the code and i changes for each loop so that each file has a different name.</p>
  
  <pre><code>DomNodeList&lt;DomElement&gt; iterable2 = page.getElementsByTagName("img");
                         Iterator&lt;DomElement&gt; i3 = iterable2.iterator();
                         int i = 0;
                         while(i3.hasNext())
                         {
                             HtmlElement element1 = null;
                              DomElement anElement = i3.next();
                              if(anElement instanceof HtmlImage)
                              {
                                   HtmlImage input = (HtmlImage) anElement;
                                   if(input.getSrcAttribute().equalsIgnoreCase("customise.gif") )
                                   {
                                        element1 = input;
                                        page2 = element1.click();
                                       webClient.waitForBackgroundJavaScript(30000);
                                       String result = page2.asText();
                                       try {
                                           BufferedWriter out = new BufferedWriter(new FileWriter("Filepath//"+customer+i+".txt"));
  
                                         out.write(result);
                                         out.close();
                                         } 
                                         catch (IOException e) 
                                         { 
                                         System.out.println("Exception ");
  
                                         }
                                      i++;
                                   }
                              }
  
                         }
  </code></pre>