Tuesday, August 9, 2016

How to handle calendar in Selenium Webdriver


jQuery UI Datepicker - Default functionality

Calendar Handle

Date:

10 comments:

  1. In "http://seleniumpractise.blogspot.in/2016/08/how-to-handle-calendar-in-selenium.html", the calender is not popping out in Firefox browser

    ReplyDelete
  2. Code is not working, it just clicks and doesnt select the date

    ReplyDelete
  3. public class DatePicker
    {
    public static void main(String[] args)
    {
    //Start browser
    WebDriver driver = new FirefoxDriver();

    //maximize browser
    driver.manage().window().maximize();

    driver.get("http://seleniumpractise.blogspot.co.uk/2016/08/how-to-handle-calendar-in-selenium.html");

    //add implicit wait
    driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

    driver.findElement(By.id("datepicker")).click();

    //find the xptah of all the TD elements
    List allDates=driver.findElements(By.xpath("//table[@class='ui-datepicker-calendar']//td"));

    for(WebElement W:allDates)
    {
    String text = W.getText();
    if(text.equalsIgnoreCase("6"))
    {
    W.click();
    break;
    }
    else
    {
    //System.out.println("Couldnt find the text");
    }
    }
    //driver.quit();
    }
    }

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. package Practice.com;

    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 Calendar {

    public static void main(String[] args)
    {
    WebDriver driver=new FirefoxDriver();
    driver.manage().window().maximize();
    driver.get("http://seleniumpractise.blogspot.in/2016/08/how-to-handle-calendar-in-selenium.html");
    //String expdt="25";
    driver.findElement(By.id("datepicker")).click();
    String caldate="26/August/2020";
    String []temp=caldate.split("/");
    String dd,mm,yy;
    dd=temp[0];
    mm=temp[1];
    yy=temp[2];
    String month,year;
    year=driver.findElement(By.className("ui-datepicker-year")).getText();
    month=driver.findElement(By.className("ui-datepicker-month")).getText();
    WebElement next=driver.findElement(By.xpath("//*[@class='ui-icon ui-icon-circle-triangle-e']"));
    while (!year.equalsIgnoreCase(yy))
    {
    driver.findElement(By.xpath("//*[@class='ui-icon ui-icon-circle-triangle-e']")).click();
    year=driver.findElement(By.className("ui-datepicker-year")).getText();
    }
    while (!month.equalsIgnoreCase(mm))
    {
    driver.findElement(By.xpath("//*[@class='ui-icon ui-icon-circle-triangle-e']")).click();
    month=driver.findElement(By.className("ui-datepicker-month")).getText();
    }

    boolean test=false;

    Listalldates=driver.findElements(By.xpath("//*[@id='ui-datepicker-div']/table//td"));
    for (int i = 0; i <alldates.size(); i++)
    {
    String date=alldates.get(i).getText();
    System.out.println(date);
    if (date.equalsIgnoreCase(dd))
    {
    System.out.println("True");
    alldates.get(i).click();
    test=true;
    System.out.println("test pass");
    break;
    }
    }






    }

    }

    ReplyDelete
  6. HI Mukesh,

    The same logic I used for my application but it is not working

    ReplyDelete
  7. I really enjoy the blog.Much thanks again. Really Great selenium Online Course Hyderabad

    ReplyDelete
  8. Hi Dear,

    i Like Your Blog Very Much..I see Daily Your Blog ,is A Very Useful For me.

    Handling LOSYCO ist ein kompetentes, spezialisiertes Unternehmen im Bereich der Produktions-Logistik. Konzipiert und realisiert werden Lean-Produktions-Systeme aus einer Hand.


    Visit site :- http://losyco.com/landingpages/handling.html

    ReplyDelete
  9. don't we have to use actions class, since we have to move the mouse over?

    ReplyDelete