Failed to enter date using sendKeys in Selenium WebDriver

The date field is like a calendar, and I cannot enter the date using sendKeys Selenium WebDriver.

But the “type” in the date field worked fine with Selenium RC.

I tried using "clear ()" before "sendKeys ()", but this gave an error:

Caught Exception: Element is read-only and so may not be used for actions Command duration or timeout: 10.11 seconds 

sendKeys () works great for other text input fields.

I tried isDisplayed () to check the item and it came as true. Even in the browser, when the test starts, the cursor moves to the date fields, but does not enter text into them.

+8
source share
5 answers

Use the 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 
+6
source

I also ran into the same problem. This is the solution I found. This worked great for me. Just remove the read-only attribute of the input field, and then do the same as the 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"); 
+3
source

For future readers of this topic, a solution was found published by @Flaburgan for the release of https://github.com/mozilla/geckodriver/issues/1070, for working with Firefox 63 on Win7-64.

"For the record, it looks like send_keys with a properly formatted ISO date (yyyy-mm-dd) works. So for your example, can you try calling send_keys with (like) 2012-11-02?"

+2
source

If you are using a jQuery date picker, the field should be read-only and the date should be selected from the calendar object. In this case, you can use the "Select" class methods for Selenium Web Driver to select a date.

 Select date = new Select(driver.findElement(By.linkText("the date want to select"))); date.click(); 
+1
source

I did this and worked great. Take care of the format. Thanks to this, you can even get the value from the control.

 var dob = element(by.id('dateOfBirth')) dob.sendKeys('20-08-1985'); expect(element(by.id('dateOfBirth')).getAttribute('value')).toBe('2015-20-08'); 

Hope this helps.

0
source

Source: https://habr.com/ru/post/925385/


All Articles