Tuesday, May 20, 2014

Selecting a date from Datepicker using Selenium WebDriver / Javascript code to pass date in datepicker

We can dynamically pass the date in Date picker field instead of selecting the date from datepicker calender.


WebElement date_element = driver.findElement(By.id(locator));
          

((JavascriptExecutor)driver).executeScript("arguments[0].value=arguments[1]", date_element, date);


Initialise the variable date as string and assign the value in required format. 
e.g String date ;
date = "01 May 2014"



2 comments:

  1. date_element, its locator and data are present in objectproperties file....can this code catch the data and laocator value from that file on the basis of the keyword datapicker/date_element. i havealready load the controllerexcel(keyword framework) file in the main textexecutor class.

    ReplyDelete