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.
however to get to the second part i need to correctly evaluate the 1st part which is the dates.
my code is below:
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;
------------ this works for me thanks for all your help -----------------
int reqIndex = 0;
dowhileloop: do {
//List<WebElement> payDates = driver.findElements(By.xpath("//table[@id='changeStartWeekGrid_rows_table']//tr[position()>1]/td[position()=5]"));
List < WebElement > 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 < String > texts = payDates.stream().map(WebElement::getText).collect(Collectors.toList());
System.out.println("date ->" + 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-> " + 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);