title: Iterating through a classname to click on all the related objects with the same classname in java for selenium
body: <p>With the test below when I am trying to iterate through the count of the elements so that all the elements that have been dragged onto a frame will be dropped back.</p>
  
  <p>To accomplish that I have written the code below, where getClass seems to be necessary to get all the elements. When getClass is removed only two elements are found and what is more bizzare is that only one element is dropped back. </p>
  
  <p>Can anyone explain why do I have to have "getClass" and is there a different way to get the entire class of a.ui-icon.ui-icon-refresh so that all the elements are clicked?</p>
  
  <pre><code>package Testing;
  import java.util.concurrent.TimeUnit;
  import org.openqa.selenium.By;
  import org.openqa.selenium.WebDriver;
  import org.openqa.selenium.WebElement;
  import org.openqa.selenium.chrome.ChromeDriver;
  import org.openqa.selenium.firefox.FirefoxDriver;
  import org.openqa.selenium.interactions.Actions;
  import java.util.Iterator;
  import java.util.List;
  
  
  public class Radiobuttons {
  
  
          public static void main(String[] args) 
      {
              // TODO Auto-generated method stub
              System.setProperty("webdriver.chrome.driver","C://chromedriver.exe");
              WebDriver driver=new ChromeDriver();
              driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
              driver.get("https://jqueryui.com/droppable/");
              System.out.println(driver.getTitle());
              WebElement SimplePhotoManager = driver.findElement(By.xpath("//*[@id=\"content\"]/div[1]/ul/li[5]/a"));
              SimplePhotoManager.click();
              driver.switchTo().frame(driver.findElement(By.xpath("//*[@id=\"content\"]/iframe")));
              WebElement source1 = driver.findElement(By.xpath("//*[@id=\"gallery\"]/li[1]"));
              WebElement source2 = driver.findElement(By.xpath("//*[@id=\"gallery\"]/li[2]"));
              WebElement source3 = driver.findElement(By.xpath("//*[@id=\"gallery\"]/li[3]"));
              WebElement source4 = driver.findElement(By.xpath("//*[@id=\"gallery\"]/li[4]"));
              WebElement targetBefore = driver.findElement(By.xpath("//*[@id=\"trash\"]"));
              Actions a = new Actions(driver);
              a.dragAndDrop(source1, targetBefore).build().perform();
              a.dragAndDrop(source2, targetBefore).build().perform();
              a.dragAndDrop(source3, targetBefore).build().perform();
              a.dragAndDrop(source4, targetBefore).build().perform();
              //Why is this required?
              List&lt;WebElement&gt; getClass= driver.findElements(By.className("a.ui-icon"));
              //Grab common attribute//Put into list and iterate
              int count=driver.findElements(By.className("ui-icon-refresh")).size();
              System.out.println(count);
              for(int i=0;i&lt;count;i++)
              {
                  driver.findElements(By.className("ui-icon-refresh")).get(i).click();
              }
  
              //Close the thing 
             //driver.quit();
      }
  
  
  }
  </code></pre>