top of page

How to handle Docker Date Picker in Selenium WebDriver

Majority of the organizations has to maintain the personal and confidential information of the users on their web applications. It is extremely important that the applications are able to capture and validate this information. The personal information has several date fields like, date of birth, issue and expiry dates for Government issued identifications, employment start and end date etc. These date fields must be tested and cover positive and negative testing scenarios. The Selenium web-driver provides a date picker object to test these fields in automation testing.

What is a date picker?

A date picker, popup calendar, date and time picker, or time picker is a graphical user interface widget which allows the user to select a date from a calendar and/or time from a time range. Date picker is a table with set of rows and columns and they are not the select element.

There are three types of date pickers:

· Docked date picker

· Modal date picker

· Modal date input

Following section shows how to select a date via Docker date picker in an automated Junit test script using the selenium WebDriver. I am presenting a dynamic approach to enter the License Expiry Date using Java Language.

Steps to handle docker date picker with a sample test case

Test Case: Validate the given integer format of the date in the in License-Expiry-Date Field which is a date field in 2001–10–05 (YYYY-DD-MM) format on My-Info page in website.

I am using JUnit framework and Chrome browser for the above test case.

Step 1: After creating Junit class, in setup() method, initiate the Chrome driver using ChromeDriver() to communicate selenium test script with google Chrome. Implicit waits to be added to provide a default waiting time between consecutive test step/command across the entire test script.

Here navigate to My-Info Page and License-Expiry-Date field on the my-info web page.

Step 2: Create a Java method for the date selection logic.

Java method:

Step3: Now call the SetDMOnCalnedar method by passing integer values to year, day and month variables


Let us see how the method works:

As we are passing integer values of year, month and date, we need to covert each value into string and matches with existing strings available in the appropriate element of the docker-date-packer. We are passing value 2001 in variable year, pattern.compile() will covert year variable into string. Matcher will match string ‘2001’ with all years available in calendar.

matcher.find() method returns true if match found else returns false.

Same logic is applied for month and day as well.

Java method to Validate Year:

This step has two types of validations:

· Year should be greater than 0.

· Year should be in the range of the year values available in the calendar.

The following snippet will explain the Java method to validate and match the entered integer value for the year to the year field of the calendar:

Java method to validate Month

After validating Year, Month is validated using the year and month values. After matching integer value to the month field of the calendar and returns month name.

Java method to validate day of the date.

This function validates the entered day of the date. It also validates the day for February month for leap and non-leap years as well.

Hope you will be able understand the above stepwise technical explanation of how to handle Selenium date picker in your automation testing. Using Selenium WebDriver, Java and Chrome browser together makes the testing of date fields efficient and effective.

Happy Learning!

84 views0 comments

Recent Posts

See All


Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page