Selenium + Python · Lesson 27 of 43

0/43 done

Module 27: Calendars & Date Pickers

27. Automating Interactive Date Pickers in Python

16 minlesson

Your task

Implement click_calendar_day(driver, day_str):

  1. driver.find_element(By.XPATH, f"//td[text()='{day_str}']").click()

Write it in the editor, then press Check answer (Ctrl + Enter).

Date Picker Automation in Python

python
# Open date picker:
driver.find_element(By.ID, "booking-date").click()

# Loop until desired month is displayed:
target_month = "November 2026"
while target_month not in driver.find_element(By.CLASS_NAME, "month-heading").text:
    driver.find_element(By.CLASS_NAME, "next-arrow").click()

# Select day:
day_to_pick = "22"
driver.find_element(By.XPATH, f"//td[contains(@class, 'day') and text()='{day_to_pick}']").click()

Key Takeaways & Walkthrough Summary

Date pickers vary from standard input fields to dynamic popup calendars. In this lesson, you will master navigating calendar months in a loop and clicking the target day cell. Let's master date pickers!

Part of the Selenium + Python course (Selenium with Python). Practice this concept live in the Selenium Online Compiler or explore our free automation practice form.

Common Doubts & Lesson Q&A

Can I just send_keys the date into the input field?

Yes, if the input is not marked readonly, driver.find_element(...).send_keys('11/22/2026') is much faster and simpler.

Ready? Solve the task in the editor

Use Check answer to mark it complete. Hints are there if you need them.

Python
Skip