title: How to click on specific element out of the webelements in selenium webdriver in java
body: <p>If the date from the list of dates is matching with the given date which is string format then it should click on that element from that list of dates which when fetched is converted to string only.
  I have list of dates like below when converted to string:  </p>
  
  <pre><code>2017-10-13  
  2017-09-29  
  2017-09-22  
  2017-09-15  
  2017-09-08  
  2017-09-01  
  2017-08-25  
  2017-08-18 
  </code></pre>
  
  <p>So now if the input which is <code>"2017-Sep-29"</code> which when parsed to another format gives <code>2017-09-29</code> matches with the second date from the list then it should be clicked but it is throwing an error.  </p>
  
  <p>Below is my java code with comments :  </p>
  
  <pre><code>WebDriver driver;
  List&lt;WebElement&gt; stageListOfFilters;
  String finalSnapshot = "", finalSnapshot1 = "";
  
  @Test
  public void getDateAndclick()
  {
  SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
      try {
          Date varDate = dateFormat.parse("18-Aug-2017");
          dateFormat = new SimpleDateFormat("yyyy-MM-dd");
          finalSnapshot1 = dateFormat.format(varDate).toString();
          System.out.println("Date: " + finalSnapshot1); // Prints 2017-08-18
          driver.findElement(By.xpath(config.getsnapshotFilter())).click();
          Thread.sleep(2000);
          finalSnap = finalSnapshot1.substring(5, 10);
          System.out.println("Date for final Comparison: " + finalSnap); // Prints 08-18 since i want to click on 18th august date
          stageListOfFilters = driver.findElements(By.xpath(".//*[@class='QvFrame DS']")); // This collects the list
                                                                                              // of dates which is
                                                                                              // fetched later on in
                                                                                              // for loop
          Thread.sleep(2000);
          for (int i = 0; i &lt; stageListOfFilters.size(); i++) {
              System.out.println(stageListOfFilters.get(i).getText());
              Thread.sleep(2000);
              if (finalSnap.contains(stageListOfFilters.get(i).getText())) {
                  driver.findElement(By.xpath(".//*[@class='QvFrame DS']/div/div/div[1]/div[2]/div[" + i + "]")) 
                          .click();// If it matches at that index then it should click on element present at that index  
                  Thread.sleep(2000);
              }
          }
      } catch (Exception e) {
          // TODO: handle exception
          e.printStackTrace();
      }
  </code></pre>
  
  <p>So now it should click on the last element since date which is being passed is <code>18th August</code> but it still clicks on <code>2017-09-29</code>. I figured out that I am not getting value using <code>get(i).getText()</code> in <code>if loop</code> which is under <code>for loop</code>. Why is it so ?<br>
  Code for getAttribute("title") data :  </p>
  
  <pre><code>stageListOfFilters = driver.findElements(By.xpath(".//*[@id='DS']")); // This collects the list
                                                                                      // of dates which is
                                                                                      // fetched later on in
                                                                                      // for loop
  
              for (WebElement element : stageListOfFilters) {
                  System.out.println("Dates are: " + element.getAttribute("title"));
              }
  </code></pre>