Date Picker Made-Easy using Selenium

Reading Time: 3 minutes

What’s this blog all about?

Folks, it’s selenium 3(stable) already! Thinking about how date picker works made me write this blog post!

As a part of learning selenium webdriver, you all must have gone through different date pickers.

Every e-commerce, banking, insurance, travel websites plus rewards and sales portals and other applications use different calendars for picking up the date.

With the course of UI enhancements in day to day life, the selenium community is upgrading itself to provide the best of methods and approaches to achieve those.

Let’s discuss a few approaches one by one.

Date picker codes

First logic goes for bootstrap calendar example :

  • Click on the calendar and current month pop-up will appear.
  • Use the findElements method to find all the dates.
  • Fetch the text of the required date and click on that.

The example goes for the following :

Second logic goes for textbox calendar example :

  • Click on the text box
  • Use the sendKeys() command to with a proper format.
  • Hence, it is the simplest way to handle the calendar in the Selenium webdriver.

second logic code goes for date range calendar example :

Third logic goes for date range calendar example :

  • Users will enter Year, Month and Day.
  • We can check the year in the first month. If the year is not the same as the required year, next arrow can be clocked until we get the required year. For example: If I need to select 2021, and the current year is 2020, we will keep on clicking the next button till we get a year like 2020.
  • Once we get the required year, we need to get the required month. And the same process is followed for the required month generation for the year.
  • Now it’s time to find the valid dates in the required month. Past dates should be filtered. We should also filter empty date columns.

References :

I hope these will help you in picking the right codes!

Written by 

Nearly 3 years of experience in automation testing, I call myself an automation enthusiast. I can create, execute automated test scripts using framework guidelines and best practices to ensure wider and efficient end-to-end automation coverage. Simultaneous experience in Defect tracking and bug reporting through JIRA

Discover more from Knoldus Blogs

Subscribe now to keep reading and get access to the full archive.

Continue reading