How to select specific date with Date Picker In Selenium WebDriver

10,848

Solution 1

Thank you guys for responded to my query... I have tried with Xpath and its works for me

Here the details:

With Below code i have been selecting Start & End date in "Date Picker"

driver.findElement(By.id("LeaveStartDate")).click();
    driver.findElement(By.className("next")).click();

    driver.findElement(By.xpath("html/body/div[8]/div[1]/table/tbody/tr[3]/td[2]")).click();
    driver.findElement(By.id("LeaveSEndDate")).click();
    driver.findElement(By.xpath("html/body/div[9]/div[1]/table/tbody/tr[3]/td[5]")).click();

Conclusion: Xpath is the solution for those who are unable to execute their selenium Java code of "Jquery Date Picker".

Solution 2

You need to locate the box that says "Start Date" and sendKeys to that element, rather than to the datepicker itself.

driver.findElement(By.id("LeaveStartDate")).sendKeys("12/10/2018");

Then do the same for the End Date.

Share:
10,848
Punit Bhagat
Author by

Punit Bhagat

Updated on June 04, 2022

Comments

  • Punit Bhagat
    Punit Bhagat almost 2 years

    I am working on Selenium WebDriver and using Java. I want to select the date range from the date picker showing in below screen.

    Currently, I am able to select date picker and change month selection but unable to select date values (i.e - 12/10/2018)

    Datepicker selection

    X

    Here the Java Code I have written:

        driver.findElement(By.linkText("Leave")).click();
        driver.findElement(By.linkText("Apply Leave")).click();
        Thread.sleep(2000);
        driver.findElement(By.id("LeaveStartDate")).click();
        driver.findElement(By.className("next")).click();
        driver.findElement(By.className("day")).sendKeys("12");
        driver.findElement(By.id("LeaveEndtDate")).click();
        driver.findElement(By.className("next")).click();
        driver.findElement(By.className("day")).sendKeys("12/11/2018");
    
    }
    }
    
    • Infern0
      Infern0 over 5 years
      can you provide HTML sample, from the image is hard to understand alot.
    • Alichino
      Alichino over 5 years
      Can you inspect the box that says "Start Date" and copy the HTML here, please?
    • Punit Bhagat
      Punit Bhagat over 5 years
      thanks guys....for helping and responded to my queries... it will worked with XPath....
  • Punit Bhagat
    Punit Bhagat over 5 years
    it will not worked for me however i have been tried with Xpath and it works for me...Thanks for the helping
  • Alichino
    Alichino over 5 years
    No worries. I assumed the Start Date field had the ID that I used :) If my answer helped you, would you pls accept it? ;)