0

I am struggling with setting date in jquery date and time picker. I am using jquery date and time picker which you can find here

I am using c# to write automated tests using selenium. Here is html for datepicker

<input data-bind="value: dateTime, disable: sending" id="datetime" type="text" class="form-control date-time" data-provide="datepicker">

I tried to set date like this

IJavaScriptExecutor js = (IJavaScriptExecutor) WebDriver;
js.ExecuteScript("document.querySelector('#datetime').value = '01/08/2019 10:40'");

But it doesnt set anything

James
  • 1,827
  • 5
  • 39
  • 69

1 Answers1

0

To set the date you have to induce WebDriverWait for the ElementToBeClickable() and you can use either of the following Locator Strategies:

  • CssSelector:

    ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].setAttribute('value','01/08/2019 10:40')", new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("input.form-control.date-time#datetime"))));
    
  • XPath:

    ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].setAttribute('value','01/08/2019 10:40')", new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//input[@class='form-control date-time' and @id='datetime']"))));
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352