Date selection is going in infinite loop | Selenium Forum
G
gautam Posted on 03/05/2021

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();
}


}