Selenium + Java · Lesson 28 of 44
Module 28: Calendars & Date Pickers
Your task
Implement selectDayInCalendar:
Write it in the editor, then press Check answer (Ctrl + Enter).
// Open calendar widget:
driver.findElement(By.id("depart-date")).click();
// Navigate to target month:
String targetMonthYear = "December 2026";
while (!driver.findElement(By.className("calendar-header")).getText().contains(targetMonthYear)) {
driver.findElement(By.className("next-month-btn")).click();
}
// Select target day:
String targetDay = "15";
driver.findElement(By.xpath("//div[@class='calendar-body']//td[text()='" + targetDay + "']")).click();Date pickers can be tricky because dates change every month and year. In this lesson, you will learn how to navigate months in a loop and click dynamic day cells reliably. Let's master date pickers!
Part of the Selenium + Java course (Selenium with Java). Practice this concept live in the Selenium Online Compiler or explore our free automation practice form.
If the input field is not readonly, sendKeys('12/15/2026') is much faster and more reliable! Always verify if direct text input is accepted.
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___