-4

In Selenium Javascript, sendKeys() is not working in Date or Time edit boxes. When I use the below code, it didn't populate the values in the appropriate fields. Is there any alternate for sendKeys()?

String strDate = "10/10/2014" ;
driver.findElement(By.xpath(DateXpath)).sendKeys(strDate);

Even I tried by hard coding the value inside sendKeys(), like driver.findElement(By.xpath(DateXpath)).sendKeys("10/10/2014"); but didn't work

henser
  • 3,307
  • 2
  • 36
  • 47
Ismail
  • 79
  • 2
  • 13
  • Can you please post the HTML code you are trying to use `sendKeys()` and also your xPath you are using to identify that element. – Jamie Rees Feb 02 '15 at 16:10
  • 2
    Did you get any exception while doing so? sometimes these date boxes will be readonly and gets populated with the calendar selection. – vins Feb 02 '15 at 16:24

2 Answers2

0

sendKeys works when that field is clicked once, before entering value, Code as follows,

driver.findElement(By.xpath(DateXpath)).click(); driver.findElement(By.xpath(DateXpath)).sendKeys("10/10/2014");

Ismail
  • 79
  • 2
  • 13
-1

Does the date box have a format displayed in it? Something like dd/MM/YYYY. If that is the case it is possible that while selenium is trying to enter values in the date field, the javscript for that date format is still running. so whatever values you enter via selenium gets very quickly over written by date format provided by javascript making it appear like your date value was never entered. You can try putting a simple delay before entering the date value.

user1019163
  • 45
  • 1
  • 2