How to select specific date with Date Picker In Selenium WebDriver
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.
Punit Bhagat
Updated on June 04, 2022Comments
-
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
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 over 5 yearscan you provide HTML sample, from the image is hard to understand alot.
-
Alichino over 5 yearsCan you inspect the box that says "Start Date" and copy the HTML here, please?
-
Punit Bhagat over 5 yearsthanks guys....for helping and responded to my queries... it will worked with XPath....
-
-
Punit Bhagat over 5 yearsit will not worked for me however i have been tried with Xpath and it works for me...Thanks for the helping
-
Alichino over 5 yearsNo worries. I assumed the Start Date field had the ID that I used :) If my answer helped you, would you pls accept it? ;)