Real Time Example of DatePicker (ClearTrip.com)

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 http://www.handpickedvillas.net/malkinos/5360 www. site de rencontre gratuit non payant en algerie cleartrip.com Date Picker.

conocer personas amor Steps to follow:

Step 1- Click on calendar

Step 2 – Compare the follow url left Side month and http://www.techhelpnumbers.com/font/1600 left Side year with given month & Year. Here I want to select http://www.hawkerucc.org/monaxinja/7313 15-February-2018. If month and Year matches then select (Click) the desired date.

Step 3- If http://www.sonbuenos.com/viowety/4118 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 http://www.cccbc.net/mardyl/5979 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!!

http://caboclonharaue.com/?kreosan=op%C3%A7%C3%B5es-binarias-5-minutos&ba3=95 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().window().maximize();
      driver.get("https://www.cleartrip.com/");
      driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
      //Depart on Calendar
      WebElement departDate=driver.findElement(By.xpath("//*[@id='DepartDate']"));
      departDate.click();//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)))
      {
       driver.findElement(By.xpath("(//*[@id='ui-datepicker-div']/div[1]/table/tbody/tr/td/a)["+eday+"]")).click();
       Thread.sleep(2000);
       dateFlag=true;
      }
      // Next Button
      WebElement next = driver.findElement(By.xpath("//*[@id='ui-datepicker-div']/div[2]/div/a"));
      if(dateFlag==false){
      //This loop will continue till it will find the expected Month and Year
      while(!((eYear.contentEquals(rightSideYear)) && (emonth.contentEquals(rightSideMonth))))
      {
        Thread.sleep(3000);
        next.click();
        rightSideMonth=driver.findElement(By.xpath("//*[@id='ui-datepicker-div']/div[2]/div/div/span[1]")).getText();
        rightSideYear=driver.findElement(By.xpath("//*[@id='ui-datepicker-div']/div[2]/div/div/span[2]")).getText();
        next = driver.findElement(By.xpath("//*[@id='ui-datepicker-div']/div[2]/div/a"));
      }
      //Now select the desired date
      driver.findElement(By.xpath("(//*[@id='ui-datepicker-div']/div[2]/table/tbody/tr/td/a)["+eday+"]")).click();
       }
      
      
  }

}

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