Real Time Example of DatePicker (

In one of my previous post, we have seen how to handle date time picker controls like jQuery date picker and Kendo date picker using Selenium WebDriver.

Since many people requested to write about real time scenario on date picker, here I am posting a real time example.

In this post, I am using www. site de rencontre gratuit non payant en algerie Date Picker.

conocer personas amor Steps to follow:

Step 1- Click on calendar

Step 2 – Compare the follow url left Side month and left Side year with given month & Year. Here I want to select 15-February-2018. If month and Year matches then select (Click) the desired date.

Step 3- If left Side month & site de rencontre croque left Side Year does not match then Compare the le meilleur site de rencontre pour jeune right Side month and right Side year with given month & Year.

Still not found the match, Click on next button and repeat it unless it found the match.

Step 4- Once month & Year matches; Select (Click) the desired date.

You are done!! Java Code:

package pack2;

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;

public class DatePicker {

  public static void main(String[] args) throws InterruptedException {
    WebDriver driver = new FirefoxDriver();
      driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
      //Depart on Calendar
      WebElement departDate=driver.findElement(By.xpath("//*[@id='DepartDate']"));;//Click on Depart on Calendar Icon
      String dateToSelect = "15-February-2018";//Here you can change the date according to your requirement with this format only
      String dateSpilitter[]=dateToSelect.split("-");//Now Separate the date,Month and Year by Splitting the String
      String eday = dateSpilitter[0];//15
      String emonth = dateSpilitter[1];//February
      String eYear = dateSpilitter[2];//2018
      //Left Side Calendar
      String leftSideMonth=driver.findElement(By.xpath("//*[@id='ui-datepicker-div']/div[1]/div/div/span[1]")).getText();
      String leftSideYear=driver.findElement(By.xpath("//*[@id='ui-datepicker-div']/div[1]/div/div/span[2]")).getText();
    //Right Side Calendar
      String rightSideMonth=driver.findElement(By.xpath("//*[@id='ui-datepicker-div']/div[2]/div/div/span[1]")).getText();
      String rightSideYear=driver.findElement(By.xpath("//*[@id='ui-datepicker-div']/div[2]/div/div/span[2]")).getText();
      boolean dateFlag=false;
      //Now check in Left side Calendar for the given date
      if((eYear.contentEquals(leftSideYear)) && (emonth.contentEquals(leftSideMonth)))
      // Next Button
      WebElement next = driver.findElement(By.xpath("//*[@id='ui-datepicker-div']/div[2]/div/a"));
      //This loop will continue till it will find the expected Month and Year
      while(!((eYear.contentEquals(rightSideYear)) && (emonth.contentEquals(rightSideMonth))))
        next = driver.findElement(By.xpath("//*[@id='ui-datepicker-div']/div[2]/div/a"));
      //Now select the desired date


Hope this helps you. If you have any query please comment below.