I am n tot able to convert/compare dates extracted from a calendar to the current date My aim is to evaluate the current date against the dates in the rows/cell and select/click the button beside the row/cell. But it is throwing an error
Below is my code:
for (WebElement pd: payDates) {
LocalDate currentDate = LocalDate.now();
java.util.Date d = new SimpleDateFormat("yyyy-MM-dd").parse(currentDate.toString());
if (pd >= (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 < 7); /// do this 7 times;
int reqIndex = 0;
dowhileloop: do {
List < WebElement > payDates = driver.findElements(By.xpath("//tr[starts-with(@id,'changeStartWeekGrid_row_')and not(starts-with(@id,'changeStartWeekGrid_row_column'))]/td[5]/span"));
List < String > texts = payDates.stream().map(WebElement::getText).collect(Collectors.toList());
System.out.println("date ->" + texts);
for (WebElement pd: payDates) {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date payDate = dateFormat.parse(pd.getText());
System.out.println("sample-> " + 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;
}
}
reqIndex++;
PS_OBJ_CycleData.Nextbtn(driver).click();
Thread.sleep(5000);