0

So, I am running some tests in headless chrome with selenium, but in headless mode the input value from this datetime field getting deleted(after its been sent) in the running process. In normal running with head the executions are okay. The datetime field is a Date type and YYYYMMDD form. date.sendKeys("19600202"); --> this is getting deleted.

But when I am sending this way, the values not getting deleted and tests runs okay:

date.sendKeys("1960");
date.sendKeys("02");
date.sendKeys("02");

Any suggestions, how can i send the Date in one sendkey or should i use js? Thank you. This is the field:

<input type="text" id="Date" ctrl_type="datetime-input" name="Date" maxlength=10 data-format="L" data-io-format="YYYYMMDD" data-today-button="false" data-clear-button="false" data-close-button="false" data-disable-weekends="false" data-inline="false" class="  form-control " data-toggle="tooltip" data-placement="top" data-original-title="" aria-describedby="_sys_invalidation-message-Date">
Guy
  • 34,831
  • 9
  • 31
  • 66
Grounder
  • 1
  • 1
  • 1-) Try to type one by one, 2-) fill it manually, and check the element for what's changed, then do the same thing with Js. (For example, you typed 19600202 and aria-describedby's text became 19600202 then u can change attribute with js) – Ahmet Aziz Beşli Feb 25 '20 at 08:40

1 Answers1

0

The desired element is an Angular element so to locate/click() on the element you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

  • cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.form-control#Date[name='Date']"))).sendKeys("19600202");
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='Date' and @name='Date'][@ctrl_type='datetime-input']"))).sendKeys("19600202");
    
DebanjanB
  • 118,661
  • 30
  • 168
  • 217