无法使用Selenium WebDriver中的sendKeys输入日期 [英] Not able to input date using sendKeys in Selenium WebDriver

查看:429
本文介绍了无法使用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

这篇关于无法使用Selenium WebDriver中的sendKeys输入日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆