Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

How To Handle Different Types Of Calendars In Selenium: Part 1 | Make Selenium Easy

Posted on 08/07/2018 By admin

Categories: Selenium Topics

Hello Folks,

In this post we will see a very important topic “Handling calendar in Selenium”.

  • We always see some input boxes where we need to select date from calendar widget. When we click on that input box, a calendar widget gets open and we need to select proper date value from that widget.
  • You can see different types of calendar widget varying across applications. For example:

MakeMyTrip.com:

Jquery Type 1:

Jquery Type 2:

  • Since every application uses different types of calendars, so it becomes little confusing and difficult to Selenium people to select date from it. You can not write a reusable method easily which can be used to handle all types of calendar.
  • Examples shown above are mostly used in applications. So I will explain handling of above calendars in this post. You can use the same logic for other types of calendar as well.

Understanding Calendar HTML:

There are so many types of calendar but there are something common across all types. We must know those common points about calendars.

  • Maximum calendars are a table which consists of rows and tables. Generally week will be created with “tr” and dates will “td”.
  • “Class” attribute for “td” tag gives more information about if date is past, current , weekend or upcoming. Refer below image, You will see the class name is different.
  • Red marked column is past date.
  • Yellow marked column is current date.
  • Green marked column is week-end.
  • Blue marked column is future date.
  • Every td will have attributes which is “data-month” and “data-year” which gives information about month and year to which td belongs. For example: “data-month” as 2 means day belongs to March month.

Handling MakeMyTrip’s calendar:

Logic:

  1. We will take Year, Month and day from user.
  2. First we will get year in first month(left hand side). If year is not matching with desired year, we will click on next till we get desired year. For example: If I need to select 2018, and current year is 2017, we will keep clicking of next button till we get year as 2018.
  3. Once we get desired year, we need to get desired month. We will retrieve month value from left most month and if month is not matching with desired month, we will keep clicking on Next button till we get desired month. For example: If current month is September and desired month is November. We will click on Next button till we get month November in left most month.
  4. The major step is finding valid dates of desired month. We should filter past dates and dates of other months. We should also filter empty date columns.
  5. Java has a number for each month of year which is equal to actual position of month-1. For example: Java month number for March will be 3-1=2.
  6. Using java month number, we can filter dates from other months.

Java Code:

Output:

You can customize and add more validation for proper valid dates. But whatever you want to do, above logic will help you in selecting date.

In upcoming posts, we will see other two types of calendar.

If you have any doubt, feel free to ask here.

If you like my posts, please like, comment, share and subscribe.

#ThanksForReading

#HappySelenium

Share

Published by

  • Selenium Topics
  • TestNG Tutorials

Hello Folks, Arguments or Parameters help us to achieve reusability of codes and cleanliness of codes. We can do overloading of…

Hello Folks, Recently I have started learning or exploring more on best practises in Selenium Framework and same I want…

  • Selenium Topics
  • TestNG Tutorials

Hello Folks, In this post we will learn below topics: 1. How to skip a test conditionally? 2. How conditionally…

  • Selenium Topics
  • TestNG Tutorials

Hello Folks, Grouping is a best feature provided by TestNG. We group test scripts based on suite name or functionality…

  • Selenium Topics
  • TestNG Tutorials

Hello Folks, Suppose you have created a testng class which has many @Test annotated methods say 10 test methods. You…

Uncategorized

Post navigation

Previous Post: TestNG Tutorials 13: Can An Interface have TestNG Methods? If Yes, How To Execute Them? | Make Selenium Easy
Next Post: TestNG Tutorials 17: Can @Test Annotation Be Used For A Class In TestNG? | Make Selenium Easy

Related Posts

TestNG Tutorials 50: DataProvider in TestNG – Understand Basics of DataProvider & How It Works Uncategorized
ScrollInToView1 – Make Selenium Easy Uncategorized
selenium tutorials Uncategorized
Black Box Testing and White Box Testing : : Everything You Need To Know Uncategorized
Core Java Quiz – 1 – Variables Uncategorized
REST Assured Tutorial 8 – BDD Style in Rest Assured Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark