The date field is like a calendar and I'm not able to input the date using sendKeys of Selenium WebDriver.
But "type" in the date field was working fine before with Selenium RC.
I tried using "clear()" before "sendKeys()" but this gave the error:
Caught Exception: Element is read-only and so may not be used for actions
Command duration or timeout: 10.11 seconds
sendKeys() is working fine for other text input fields.
I tried isDisplayed() to check for the element and it comes as true. Even in the browser, when running the test, the cursor goes to the date fields but doesnt type any text into them.
Use Following Code for this...
((JavascriptExecutor)driver).executeScript ("document.getElementById('dateofbirth').removeAttribute('readonly',0);");
WebElement BirthDate= driver.findElement(By.id("dateofbirth"));
BirthDate.clear();
BirthDate.sendKeys("20-Aug-1985"); //Enter this date details with valid date format
I also faced the same issue.This is what the solution I found.This worked fine for me. Just remove the read only attribute of the input field and then do just as other input fields.
((JavascriptExecutor) driver).executeScript("document.getElementsByName('date'[0].removeAttribute('readonly');");
WebElement dateFld = driver.findElement(By.id("date_completed"));
dateFld.clear();
dateFld.sendKeys("date Completed");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With