How to Select Date from DatePicker in Selenium Webdriver

http://www.fbtaudio.co.uk/?mirta=site-de-rencontre-serieux-au-quebec&a44=c6 http://www.cutebonsaitree.com/frnew1/10139 How to Select Date from DatePicker in Selenium Webdriver

site de rencontre franГ§ais gratuit 2015 In this post, we’ll learn how to handle date time picker controls like jQuery date picker and Kendo date picker using Selenium Webdriver.

sitios de citas ecuador I will use JQuery Date picker for example and you can take any example because approach will remain same.

Full Article Below image is an example of Date picker which is JQuery widget

nsi online dating contact number

http://bossons-fute.fr/?fimerois=rencontres-amicales-en-belgique&ad6=72 Link for above Calendar: http://jqueryui.com/resources/demos/datepicker/other-months.html

here http://www.mylifept.com/?refriwerator=early-closure-bei-bin%C3%A4ren-optionen&f46=a6 early closure bei binären optionen Steps to follow:

Step 1- Click on calendar

Step 2 – Get the month and year from the Calander by getText() method.

Step 3- Compare the month & Year with given month & Year. Here I want to Select 15-January-2018, but the extracted month and year is October 2017.

Step 4- If month & Year does not matches then Click on next button and repeat Step no 3 unless it found the match.

Step 5- Once month & Year matches, it’s time to select day. Using for loop get text of all elements using if else condition we will check specific date

Step 6- If date is matched then click and break the loop.

You are done !!

package pack7;

import java.util.List;

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

public class CalendarProgram {
  public static void main(String[] args) throws InterruptedException {
  
  WebDriver driver = new FirefoxDriver();
  driver.manage().window().maximize();
  driver.get("http://jqueryui.com/resources/demos/datepicker/other-months.html");
  WebElement calElement=driver.findElement(By.id("datepicker"));
  calElement.click();
  String date = "15-January-2018";
  String spilitter[]=date.split("-");
  String eday = spilitter[0];
  String emonth = spilitter[1];
  String eYear = spilitter[2];
  
  String oMonth=driver.findElement(By.xpath("//*[@id='ui-datepicker-div']/div/div/span[1]")).getText();
  String oYear=driver.findElement(By.xpath("//*[@id='ui-datepicker-div']/div/div/span[2]")).getText();
  System.out.println(oMonth);
  System.out.println(oYear);
  
  WebElement Next = driver.findElement(By.xpath("//span[contains(text(),'Next')]"));// Next Button
  
  while(!((eYear.contentEquals(oYear)) && (emonth.contentEquals(oMonth))))
  {
    Thread.sleep(2000);
    Next.click();
    oMonth=driver.findElement(By.xpath("//*[@id='ui-datepicker-div']/div/div/span[1]")).getText();
    oYear=driver.findElement(By.xpath("//*[@id='ui-datepicker-div']/div/div/span[2]")).getText();
    Next = driver.findElement(By.xpath("//span[contains(text(),'Next')]"));
  }
  System.out.println("M here");
  WebElement tBody = driver.findElement(By.xpath("//*[@id='ui-datepicker-div']/table/tbody"));
  List<WebElement> tRow = tBody.findElements(By.tagName("tr"));
  
  for(int i=1;i<=tRow.size();i++)
  {
    List<WebElement> tColoumn = tRow.get(i).findElements(By.tagName("td"));
    
    for(int j=1;j<=tColoumn.size();j++)
    {
      String oDay = driver.findElement(By.xpath("//*[@id='ui-datepicker-div']/table/tbody/tr["+i+"]/td["+j+"]/a")).getText();
      if(eday.equals(oDay))
      {
        driver.findElement(By.xpath("//*[@id='ui-datepicker-div']/table/tbody/tr["+i+"]/td["+j+"]")).click();
        break;
      }
    }
  }
}
}