selenium webdriver自动化对日期控件的处理

来源:互联网 发布:兰州大学怎么样知乎 编辑:程序博客网 时间:2024/06/15 08:29
用JS去掉日期输入框的readOnly属性。

代码如下:

-------------------------------------------------------------------------------------

String js="document.getElementById('dateTimeId').removeAttribute('readOnly');document.getElementById('dateTimeId').setAttribute('value','2012-10-25');";

((JavascriptExecutor) driver).executeScript(js);

--------------------------------------------------------------------------------------

getElementById('dateTimeId')

也可以用其他方式获取元素,如:getElementByName('dateTimeIdName')。。。。。

用这种方法比较简便,不过有一个缺点,因为是直接给日期输入框赋值,所以无法验证日期控件是否正常。

 

0 0
原创粉丝点击