0

Unable to set value to DatePicker-Selenium WebDriver using JavascriptExecutor

public class CopyOfDatePicker {
public static void main(String[] args) throws InterruptedException {
    System.setProperty("webdriver.chrome.driver","D://Drivers//chromedriver_win32//chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.get("https://www.spicejet.com/");
    Thread.sleep(6000);
    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("document.getElementById('ctl00_mainContent_txt_Fromdate').value='11-02-2019'");
}

}

1 Answers1

0

I would suggest you not to inject javascript as it is really a bad practice. You might miss some potential issues as it would not call any associated events.

Check this post which explains how to automate date picker - there is a demo as well to show how it works.

http://www.testautomationguru.com/selenium-webdriver-automating-custom-controls-datepicker/

vins
  • 15,030
  • 3
  • 36
  • 47