Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
330 views
in Technique[技术] by (71.8m points)

java - Not able to input date using sendKeys in Selenium WebDriver

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...