Coding Fun Java Handling Datepicker in Selenium using JavascriptExecutor – Java

Handling Datepicker in Selenium using JavascriptExecutor – Java

Handling Datepicker using JavascriptExecutor – Java is one of the most important topics in Selenium. We can handle this scenario very easily using JavaScriptExecutor in the selenium web driver.

Facebook :
Linkedin :
Google+ :
Twitter :

Tags: , , , , , , , , , , , , , , , , ,

18 thoughts on “Handling Datepicker in Selenium using JavascriptExecutor – Java”

  1. Sir, please explain how to automate 2nd type of date picker(DatePicker Enabled)

  2. Rajesh devan says:

    Thank you Sir for this video

  3. Your a life saver, many thanks!!

  4. Tushar Khade says:

    Krushna can you share your mobile number?

  5. Hi
    HTML :
    <p class="input-group">
    <input class="form-control ng-isolate-scope ng-valid-date ng-touched ng-not-empty ng-dirty ng-valid ng-valid-required" type="text" close-text="Close" readonly="true" ng-required="true" datepicker-options="dateOptions" is-open="popup1.opened" ng-model-options="{timezone:'UTC'}" ng-model="addeditcampaigntag.dt_startdate" ng-change="isstartDateChange(savedstartdateondb, savedenddateondb, addeditcampaigntag.dt_startdate, addeditcampaigntag.dt_enddate)" uib-datepicker-popup="yyyy/MM/dd" placeholder="Start Date" required="required" style="">

    my code :
    JavascriptExecutor js = (JavascriptExecutor)driver;
    js.executeScript("document.querySelector('.form-control ng-pristine ng-isolate-scope ng-empty ng-invalid ng-invalid-required ng-valid-date ng-touched').value='2018/08/19'");

    i am getting : org.openqa.selenium.WebDriverException: unknown error: Cannot set property 'value' of null

    how can i write the Java script to this ?

  6. Yogi Ganpule says:

    I have this html

    <button autoid="_dx_0" type="button" class="_dx_2 ms-fcl-ns ms-bgc-w ms-bcl-nta" aria-owns="_ariaId_94" aria-haspopup="true" role="combobox" aria-label="start date Monday, June 11, 2018"><span class="_dx_4 ms-fwt-sl ms-font-s">Mon 6/11/2018</span><span class="_dx_5 owaimg ms-Icon–calendar ms-icon-tall-glyph ms-icon-font-size-16 ms-fcl-ns-b"> </span></button>

    i am unable to access please help
    other question is how do i select multiple dates when its disabled date pickers ?

  7. Krishna could you please make a video on handling tree view using selenium

  8. M S says:

    can the date selection be done using chrome browser ? i have checked many videos but all use firefox browser.

  9. Thank you so much. Subscribed your channel 😉

  10. Megha P says:


    How to pass variable instead of value in JavascriptExecutor,

    Below code is not working for me:
    firstname= randomstring();

  11. thanks a lot … word to say how easy you explain it

  12. Cloudy Day says:

    It worked for me, thanks for sharing

  13. driver.get("");

    driver.findElement(By.xpath("//*[@class='icon ui_icon flights']")).click();
    driver.findElement("metaFlightFrom")).sendKeys("New York City, NY – John F. Kennedy International Airport (JFK)");

    driver.findElement("metaFlightTo")).sendKeys("Dhaka, Bangladesh – Zia Intl (DAC)");

    JavascriptExecutor ckIn = (JavascriptExecutor)driver;

    JavascriptExecutor ckOut = (JavascriptExecutor)driver;

    Select pick = new Select(driver.findElement(By.xpath(".//*[@id='fadults']")));
    pick.selectByVisibleText("2 travelers");


  14. Thanks. i tried this method on TripAdvisor website and it worked perfectly.

  15. Please fix it as early as possible.

  16. Hello Krishna Sakinala. I am not able to open your website due to this error
    Error establishing a database connection

  17. its not working for me . giving error"unknown error: document.getElementByID is not a function" please help

  18. nv sateesh says:

    If we have id or css selector then below are the ways to handle

    —id of an element

     JavascriptExecutor js = (JavascriptExecutor)driver;        js.executeScript("document.getElementById('datepicker1').value = '09/12/2020';");
    —- css selector of an element ——-

    JavascriptExecutor js = (JavascriptExecutor)driver;        js.executeScript("document.querySelector('#datepicker1').value='09/12/2020';");
    If an element having only name or class (i want to use xpath) then below code is right or not ? Please reply and provide syntax too………….


Leave a Reply

Your email address will not be published. Required fields are marked *