---
description: This tutorial gives stepwise details to select Date form DatePicker in a Calendar using Selenium Webdriver
title: How to Select Date from DatePicker/Calendar in Selenium Webdriver
image: https://www.guru99.com/images/AdvanceSelenium/071514_0744_HandlingDat1.png
---

 

[Skip to content](#main) 

## How to Handle Calendar in Selenium

For DateTime selection, HTML5 has a new control shown below.

[![Handle Calendar in Selenium](https://www.guru99.com/images/AdvanceSelenium/071514_0744_HandlingDat1.png)](https://www.guru99.com/images/AdvanceSelenium/071514%5F0744%5FHandlingDat1.png)

Above page can be accessed here: <https://demo.guru99.com/test/>

If we see the DOM of the DateTime Picker control, there will be only one input box for both date and time.

[![Handle Calendar in Selenium](https://www.guru99.com/images/AdvanceSelenium/071514_0744_HandlingDat2.png)](https://www.guru99.com/images/AdvanceSelenium/071514%5F0744%5FHandlingDat2.png)

  
So to handle this type of control first we will fill date without separating with delimiter, i.e. if date is 09/25/2013, then we will pass 09252013 to the input box. Once done, we will shift focus from date to time by pressing ‘tab’ & fill time. 

If we need to fill 02:45 PM , we will pass it a ‘0245PM’ to the same input box.

The code for datepicker looks like this –

import java.util.List;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;

import org.openqa.selenium.Keys;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.annotations.Test;

public class DateTimePicker {

    @Test

    public void dateTimePicker(){

        System.setProperty("webdriver.chrome.driver", "chromedriver.exe");

        WebDriver driver = new ChromeDriver();

        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        driver.get("https://demo.guru99.com/test/");

        //Find the date time picker control

        WebElement dateBox = driver.findElement(By.xpath("//form//input[@name='bdaytime']"));

        //Fill date as mm/dd/yyyy as 09/25/2013

        dateBox.sendKeys("09252013");

        //Press tab to shift focus to time field

        dateBox.sendKeys(Keys.TAB);

        //Fill time as 02:45 PM

        dateBox.sendKeys("0245PM");

    }

    }

### RELATED ARTICLES

* [What is Selenium? Introduction Tutorial ](https://www.guru99.com/introduction-to-selenium.html "What is Selenium? Introduction Tutorial")
* [Robot Class in Selenium Webdriver ](https://www.guru99.com/using-robot-api-selenium.html "Robot Class in Selenium Webdriver")
* [How to Handle iFrames in Selenium Webdriver: switchTo() ](https://www.guru99.com/handling-iframes-selenium.html "How to Handle iFrames in Selenium Webdriver: switchTo()")
* [Selenium Quiz: MCQ Questions & Answers, Online Mock Test ](https://www.guru99.com/selenium-certification-quiz.html "Selenium Quiz: MCQ Questions & Answers, Online Mock Test")

  
Output will be like- 

[](https://www.guru99.com/images/AdvanceSelenium/071514%5F0744%5FHandlingDat3.png)

Lets look at another Calendar example. We will use Telerik DateTimePicker control. Can be accessed [here](https://demos.telerik.com/kendo-ui/datetimepicker/index)

[](https://www.guru99.com/images/AdvanceSelenium/071514%5F0744%5FHandlingDat4.png)

Here if we need to change the month, we have to click on the middle of the calendar header.  

[](https://www.guru99.com/images/AdvanceSelenium/071514%5F0744%5FHandlingDat5.png)

Similarly if we need to change the year then we can do it by clicking next or previous links on the datepicker.

[](https://www.guru99.com/images/AdvanceSelenium/071514%5F0744%5FHandlingDat6.png)

And finally for changing the time we can select correct time from the dropdown(Note: Here time is selected in a gap of 30 min. i.e., 12:00, 12:30 , 1:00, 1:30 etc.).

[](https://www.guru99.com/images/AdvanceSelenium/071514%5F0744%5FHandlingDat7.png)

A complete example looks like-

import java.util.Calendar;

import java.util.List;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.testng.annotations.Test;

public class DatePicker {

    @Test

    public void testDAtePicker() throws Exception{

        //DAte and Time to be set in textbox

        String dateTime ="12/07/2014 2:00 PM";

        WebDriver driver = new FirefoxDriver();

        driver.manage().window().maximize();
        
        driver.get("https://demos.telerik.com/kendo-ui/datetimepicker/index");
        
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        
        //button to open calendar

        WebElement selectDate = driver.findElement(By.xpath("//span[@aria-controls='datetimepicker_dateview']"));
        
    selectDate.click();

    //button to move next in calendar

    WebElement nextLink = driver.findElement(By.xpath("//div[@id='datetimepicker_dateview']//div[@class='k-header']//a[contains(@class,'k-nav-next')]"));

    //button to click in center of calendar header

    WebElement midLink = driver.findElement(By.xpath("//div[@id='datetimepicker_dateview']//div[@class='k-header']//a[contains(@class,'k-nav-fast')]"));

    //button to move previous month in calendar

    WebElement previousLink = driver.findElement(By.xpath("//div[@id='datetimepicker_dateview']//div[@class='k-header']//a[contains(@class,'k-nav-prev')]")); 

        //Split the date time to get only the date part

        String date_dd_MM_yyyy[] = (dateTime.split(" ")[0]).split("/");

        //get the year difference between current year and year to set in calander

        int yearDiff = Integer.parseInt(date_dd_MM_yyyy[2])- Calendar.getInstance().get(Calendar.YEAR);

        midLink.click();

        if(yearDiff!=0){

            //if you have to move next year

            if(yearDiff>0){

                for(int i=0;i< yearDiff;i++){

                    System.out.println("Year Diff->"+i);

                    nextLink.click();

                }

            }

            //if you have to move previous year

            else if(yearDiff<0){

                for(int i=0;i< (yearDiff*(-1));i++){

                    System.out.println("Year Diff->"+i);

                    previousLink.click();

                }

            }

        }
        
        Thread.sleep(1000);

        //Get all months from calendar to select correct one

        List<WebElement> list_AllMonthToBook = driver.findElements(By.xpath("//div[@id='datetimepicker_dateview']//table//tbody//td[not(contains(@class,'k-other-month'))]"));
        
        list_AllMonthToBook.get(Integer.parseInt(date_dd_MM_yyyy[1])-1).click();
        
        Thread.sleep(1000);

        //get all dates from calendar to select correct one

        List<WebElement> list_AllDateToBook = driver.findElements(By.xpath("//div[@id='datetimepicker_dateview']//table//tbody//td[not(contains(@class,'k-other-month'))]"));
        
        list_AllDateToBook.get(Integer.parseInt(date_dd_MM_yyyy[0])-1).click();
        
        ///FOR TIME

        WebElement selectTime = driver.findElement(By.xpath("//span[@aria-controls='datetimepicker_timeview']"));

        //click time picker button

        selectTime.click();

        //get list of times

        List<WebElement> allTime = driver.findElements(By.xpath("//div[@data-role='popup'][contains(@style,'display: block')]//ul//li[@role='option']"));
      
        dateTime = dateTime.split(" ")[1]+" "+dateTime.split(" ")[2];

     //select correct time

        for (WebElement webElement : allTime) {

            if(webElement.getText().equalsIgnoreCase(dateTime))

            {

                webElement.click();

            }

        }

    }

}

Output will be like

[](https://www.guru99.com/images/AdvanceSelenium/071514%5F0744%5FHandlingDat8.png)

#### Summarize this post with:

ChatGPT Perplexity Grok Google AI 

**Stay Updated on AI** **Get Weekly AI Skills, Trends, Actionable Advice.** 

##### Sign up for the newsletter

Subscribe for Free 

You have successfully subscribed.  
Please check your inbox. 

![AI-Newsletter]() Chosen by over **350,000+** professionals 

[Scroll to top ](#wrapper)Scroll to top 

× 

Toggle Menu Close 

Search for: 

Search

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.guru99.com/#organization","name":"Guru99","sameAs":["https://www.facebook.com/Guru99Official","https://twitter.com/guru99com"],"logo":{"@type":"ImageObject","@id":"https://www.guru99.com/#logo","url":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","contentUrl":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","caption":"Guru99","inLanguage":"en-US"}},{"@type":"WebSite","@id":"https://www.guru99.com/#website","url":"https://www.guru99.com","name":"Guru99","publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https://www.guru99.com/images/handling-date-time-picker.png","url":"https://www.guru99.com/images/handling-date-time-picker.png","width":"468","height":"165","inLanguage":"en-US"},{"@type":"BreadcrumbList","@id":"https://www.guru99.com/handling-date-time-picker-using-selenium.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":"1","item":{"@id":"https://www.guru99.com","name":"Home"}},{"@type":"ListItem","position":"2","item":{"@id":"https://www.guru99.com/selenium","name":"Selenium"}},{"@type":"ListItem","position":"3","item":{"@id":"https://www.guru99.com/handling-date-time-picker-using-selenium.html","name":"How to Select Date from DatePicker/Calendar in Selenium Webdriver"}}]},{"@type":"WebPage","@id":"https://www.guru99.com/handling-date-time-picker-using-selenium.html#webpage","url":"https://www.guru99.com/handling-date-time-picker-using-selenium.html","name":"How to Select Date from DatePicker/Calendar in Selenium Webdriver","dateModified":"2025-05-02T17:03:20+05:30","isPartOf":{"@id":"https://www.guru99.com/#website"},"primaryImageOfPage":{"@id":"https://www.guru99.com/images/handling-date-time-picker.png"},"inLanguage":"en-US","breadcrumb":{"@id":"https://www.guru99.com/handling-date-time-picker-using-selenium.html#breadcrumb"}},{"@type":"Person","@id":"https://www.guru99.com/author/admin","name":"Krishna Rungta","url":"https://www.guru99.com/author/admin","image":{"@type":"ImageObject","@id":"https://www.guru99.com/images/krishna-rungta-v2-120x120.png","url":"https://www.guru99.com/images/krishna-rungta-v2-120x120.png","caption":"Krishna Rungta","inLanguage":"en-US"},"worksFor":{"@id":"https://www.guru99.com/#organization"}},{"articleSection":"Selenium","headline":"How to Select Date from DatePicker/Calendar in Selenium Webdriver","description":"This tutorial gives stepwise details to select Date form DatePicker in a Calendar using Selenium Webdriver","keywords":"selenium","speakable":{"@type":"SpeakableSpecification","cssSelector":[".entry-title",".summary"]},"@type":"Article","author":{"@id":"https://www.guru99.com/author/admin","name":"Krishna Rungta"},"dateModified":"2025-05-02T17:03:20+05:30","image":{"@id":"https://www.guru99.com/images/handling-date-time-picker.png"},"copyrightYear":"2025","name":"How to Select Date from DatePicker/Calendar in Selenium Webdriver","subjectOf":[{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"Why use explicit waits when handling a datepicker?","acceptedAnswer":{"@type":"Answer","text":"Calendar widgets load dynamically, so WebDriverWait ensures the date element is clickable, preventing NoSuchElementException errors."}},{"@type":"Question","name":"Can AI automate datepicker selection in Selenium?","acceptedAnswer":{"@type":"Answer","text":"Yes. AI tools generate locators, self-heal broken XPaths when markup changes, and suggest wait strategies, cutting maintenance."}},{"@type":"Question","name":"How does AI handle different datepicker types?","acceptedAnswer":{"@type":"Answer","text":"AI-driven tools detect whether a calendar uses jQuery UI, Bootstrap, or React, then adapt selection logic."}}]}],"@id":"https://www.guru99.com/handling-date-time-picker-using-selenium.html#schema-1125100","isPartOf":{"@id":"https://www.guru99.com/handling-date-time-picker-using-selenium.html#webpage"},"publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US","mainEntityOfPage":{"@id":"https://www.guru99.com/handling-date-time-picker-using-selenium.html#webpage"}}]}
```
