Please look at my code and it doesn't work.
//start the browser
WebDriver driver = new FirefoxDriver();
//Open the URL
driver.get("
https://www.redbus.in/");
//maximize the window
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//click on the Date Picker
Thread.sleep(10000);
driver.findElement(By.xpath(".//*[@id='txtOnwardCalendar']")).click();
//now find the xpath for the main table of Date picker
String Date_Table = "//div[@id='rbcal_txtOnwardCalendar']/table[1]//td";
//store elements i.e dates in a list
WebElement Dates = driver.findElement(By.xpath(Date_Table));
List<WebElement> columns = Dates.findElements(By.tagName("td"));
//find the no of elements
for ( WebElement cell : columns)
{
if (cell.getText().equals(31))
{
cell.findElement(By.xpath(".//*[@id='rbcal_txtOnwardCalendar']/table[1]/tbody//td[contains(text(),'31')]")).click();
break;
}
}
/*
//run a for loop to find the the specified element
for ( int i=0; i<Date_nodes; i++)
{
String date_value = Dates.get(i).getText();
if (date_value.equals(31))
{
Dates.get(i).findElement(By.xpath("//div[@id='rbcal_txtOnwardCalendar']/table[1]//td[contains(text(),'31')]"));
break;
}
}*/
System.out.println("Date is selected");
//end of for loop
}//end of function
}//end of class