title: Creating Date Object and Compare Dates
body: <p>I am having trouble converting/comparing dates extracted from a calendar to the current date I get a red line in eclipse under my if statement My goal is to evaluate the current date against the dates in the rows/cell and select/click the button beside the row/cell.</p>
  
  <p>however to get to the second part i need to correctly evaluate the 1st part which is the dates.</p>
  
  <p>my code is below:</p>
  
  <pre><code> for (WebElement pd: payDates) {
  
    LocalDate currentDate = LocalDate.now();
    java.util.Date d = new SimpleDateFormat("yyyy-MM-dd").parse(currentDate.toString());
  
    if (pd &gt;= (d)) {
     driver.findElement(By.xpath("//tr[starts-with(@id,'changeStartWeekGrid_row_')and not(starts-with(@id,'changeStartWeekGrid_row_column'))]/td[5]/span'" + reqIndex + "])/TBODY[@id='changeStartWeekGrid_rows_tbody']/TR[7]/TD[1]/DIV[1]/DIV[1]/DIV[1]")).click();
     PS_OBJ_CycleData.donebtn(driver).click();
     break;
    } else {
     reqIndex++;
     PS_OBJ_CycleData.Nextbtn(driver).click();
    }
  
   }
  } while (reqIndex &lt; 7); /// do this 7 times;
  
  ------------ this works for me thanks for all your help -----------------
   int reqIndex = 0;
  
   dowhileloop: do {
     //List&lt;WebElement&gt; payDates = driver.findElements(By.xpath("//table[@id='changeStartWeekGrid_rows_table']//tr[position()&gt;1]/td[position()=5]"));
     List &lt; WebElement &gt; payDates = driver.findElements(By.xpath("//tr[starts-with(@id,'changeStartWeekGrid_row_')and not(starts-with(@id,'changeStartWeekGrid_row_column'))]/td[5]/span"));
  
     // 5th colunm date print test
     List &lt; String &gt; texts = payDates.stream().map(WebElement::getText).collect(Collectors.toList());
     System.out.println("date -&gt;" + texts);
  
     //** Begin third inner for-loop****
     for (WebElement pd: payDates) { // begin inner for loop
      SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
      Date payDate = dateFormat.parse(pd.getText());
      System.out.println("sample-&gt; " + dateFormat.format(payDate));
  
      if (payDate.after(new Date())) {
       System.out.println("inside for loop");
       driver.findElement(By.xpath("//tr[starts-with(@id,'changeStartWeekGrid_row_')and not(starts-with(@id,'changeStartWeekGrid_row_column'))]/td[5]/span'" + reqIndex + "])/TBODY[@id='changeStartWeekGrid_rows_tbody']/TR[7]/TD[1]/DIV[1]/DIV[1]/DIV[1]")).click();
       PS_OBJ_CycleData.donebtn(driver).click();
       break dowhileloop;
      }
  
     } //** END third inner for-loop****
     reqIndex++;
     PS_OBJ_CycleData.Nextbtn(driver).click();
     Thread.sleep(5000);
  </code></pre>