Reputation: 11
The calendar display date from current to next upcoming date. i need to select current date when every time I run the script.
Calendar looks like this: https://www.screencast.com/t/EWjncok2Anv
I tried with below code, but didn't help me:
DateFormat dateFormat2 = new SimpleDateFormat("dd");
Date date2 = new Date();
String today = dateFormat2.format(date2);
//find the calendar
WebElement dateWidget = driver.findElement(By.id("qs_startdate"));
List<WebElement> columns=dateWidget.findElements(By.tagName("div"));
//comparing the text of cell with today's date and clicking it.
for (WebElement cell : columns)
{
if (cell.getText().equals(today))
{
cell.click();
break;
}
}
Upvotes: 1
Views: 12656
Reputation: 154
Try this -
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yy");
Date today = Calendar.getInstance().getTime();
String date = dateFormat.format(today);
Upvotes: 0