"environmental information"
python34+ie+windows2008
Description
1, for the date control, there is no way to locate the element and then directly pass the value of Processing. You can use the Execute JavaScript processing.
PS: also want to learn how to write js, otherwise it will only be used when the copy is Everywhere.
Example
1, for the following format date control needs to use JS Processing.
2, processing method: through Driver.execute_script (js) Execution.
#problem Elimination time, invoking Js's current timeJS ="function Getcurrentdate () {" "var dtcur = new Date ();" "var yearcur = dtcur.getfullyear ();" "var moncur = dtcur.getmonth () + 1;" "var daycur = dtcur.getdate ();" "var hcur = dtcur.gethours ();" "var mcur = dtcur.getminutes ();" "var scur = dtcur.getseconds ();" "var timecur = yearcur + \ "-\" + (moncur < "0\" + moncur:moncur) + \ "-\"" "+ (daycur < "0\" + Daycur:daycur) + \ "+" + (hcur < "0\" + Hcur:hcur)" "+ \ ": \" + (mcur < "0\" + mcur:mcur) + \ ": \" + (scur < "0\" + scur:scur);" "return timecur;" " }" "var value = document.getElementById (\ "issueeliminattime\");" "Value.removeattribute (\ "readonly\");" "value.setattribute (\ "value\", getcurrentdate ());"Self.driver.execute_script (js)
3, for the time of the JS processing Mode.
The time format is: 2017-02-16 17:34:18
function getcurrentdate (count) {var dtcur=New Date (); #The statement is a time offset, such as to obtain a time that is 2 hours later than the current time, and count can pass in 2 #when you need to obtain a time later than the current day, you can change the gethours () to getdate (). for minutes and seconds.Dtcur.sethours (dtcur.gethours () +count); var yearcur=Dtcur.getfullyear (); var moncur= Dtcur.getmonth () +1; var daycur=dtcur.getdate (); var hcur=dtcur.gethours (); var mcur=dtcur.getminutes (); var scur=Dtcur.getseconds (); var timecur= Yearcur +"-"+ (moncur < 10?)"0"+ Moncur:moncur) +"-"+ (daycur < 10?)"0"+ Daycur:daycur) +" "+ (hcur < 10?)"0"+Hcur:hcur)+":"+ (mcur < 10?)"0"+ Mcur:mcur) +":"+ (scur < 10?)"0"+scur:scur); returntimecur; }
Python+selenium processing the date control (with the execution JS Script)