My Date selection is going in infinite while loop. Code is clicking on previos.
Not sure where ia m doing wrong.
Please help.
Below is the code:
public void selectDate(String ProvideDate) {
String DateDisplayed = driver.findElement(By.xpath(prop.getProperty("datedisplayed"))).getText();
System.out.println(DateDisplayed);
SimpleDateFormat sd = new SimpleDateFormat("dd-MM-yyyy");
try {
Date DateToBeSelected = sd.parse(ProvideDate);
Date currentDate = new Date();
System.out.println(currentDate);
System.out.println(DateToBeSelected);
String day = new SimpleDateFormat("dd").format(DateToBeSelected);
//System.out.println(day);
String month = new SimpleDateFormat("MMMM").format(DateToBeSelected);
//System.out.println(month);
String year = new SimpleDateFormat("yyyy").format(DateToBeSelected);
//System.out.println(year);
String MonthYeartobeselected = month+" "+year;
System.out.println(MonthYeartobeselected);
while(!MonthYeartobeselected.equals(DateDisplayed)){
if(DateToBeSelected.compareTo(currentDate)==1) {
driver.findElement(By.xpath(prop.getProperty("next"))).click();
}else if(DateToBeSelected.compareTo(currentDate)==-1) {
driver.findElement(By.xpath(prop.getProperty("prev"))).click();
}
}
Instructor
Ashish Thakur Replied on 18/05/2021
I am sorry for late reply. I was not well
Is it fixed?
Yes Ashish it is fixed.
Thanks