python webdriver调用JS操作日期控件

来源:互联网 发布:mac ntfs 移动硬盘 编辑:程序博客网 时间:2024/05/16 05:20

前提:日期控件存有readonly属性

步骤:

1.将input标签的readonly熟悉去掉,并对日期控件赋值

js="document.getElementById(\'birthday\').removeAttribute('readonly');document.getElementById(\'birthday\').setAttribute('value','2016-11-23');"

2.执行JS

 driver.execute_script(js)

即可成功对存有readonly属性的日期控件输入日期。


备注:若在赋值时,赋一参数(本例:birthday),日期控件中会显示为 [object HTMLInputElement],解决方法暂不会,在此记录一下。

例:

js="document.getElementById(\'birthday\').removeAttribute('readonly');document.getElementById(\'birthday\').setAttribute('value',birthday);"

0 0
原创粉丝点击