无法使用Selenium WebDriver中的sendKeys输入日期

无法使用Selenium WebDriver中的sendKeys输入日期

问题描述:

日期字段就像一个日历,我无法使用Selenium WebDriver的sendKeys输入日期。

The date field is like a calendar and I'm not able to input the date using sendKeys of Selenium WebDriver.

但是在使用Selenium RC之前,日期字段中的type工作正常。

But "type" in the date field was working fine before with Selenium RC.

我试过用 clear()beforesendKeys()但是这给出了错误:

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()是适用于其他文本输入字段。

sendKeys() is working fine for other text input fields.

我尝试使用isDisplayed()来检查元素,它是真的。即使在浏览器中,当运行测试时,光标也会转到日期字段,但不会在其中键入任何文本。

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.

使用以下代码...

((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