Showing posts with label calendar. Show all posts
Showing posts with label calendar. Show all posts

Saturday, June 21, 2014

How to select desired date from the calendar pop-up ?

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 CalenderPopUp {
   
     public static void main(String[] args) {
     int day, month, year;
   
     String futrDate = "td_"+2015+"_"+06+"_"+24; //this is the 'id' format in the calendar popup in html code, ex- id=td_2015_6_24
   
     WebDriver driver = new FirefoxDriver();
     driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
     driver.get("http://www.yatra.com/");
   
     driver.findElement(By.id("BE_flight_depart_date")).click();
     String monthYear="";
     //this loop will execute untill your required month and year will not appear in the calendar
     //here you can also pass the input from your and by making code as common
     while(!(monthYear.equals("June 2015"))){
         driver.findElement(By.xpath("//a[@class='js_btnNext sprite nextBtn']")).click(); //this will click on next button for month
         monthYear = driver.findElement(By.xpath("//span[@class='js_monthTitle']")).getText(); // this is to get the month and year from calendar pop up
     }
   
     driver.findElement(By.xpath("//td[@id='"+futrDate+"']")).click(); //this will select the date
     }
}

Sunday, May 18, 2014

How to handle calender popup or date picker ?

Note- 1st click on the calendar button then click on the date which you want to select.
Here in the below example, it will always select the current date , you can pass any date which you want to select as per your requirement.


import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

    public class TodayDate {
    public static void main(String[] args) {
        int day, month, year;
          GregorianCalendar date = new GregorianCalendar();
          day = date.get(Calendar.DAY_OF_MONTH);
          month = date.get(Calendar.MONTH)+1;
          year = date.get(Calendar.YEAR);
          String today = "a_"+year+"_"+month+"_"+day;
          System.out.println(today);
    WebDriver driver = new FirefoxDriver();
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    driver.get("http://www.yatra.com/");
    driver.findElement(By.id("BE_flight_depart_date")).click();
    driver.findElement(By.xpath("//a[@id='"+today+"']")).click();
   
    }

    }