Python+selenium processing the date control (with the execution JS Script)

Source: Internet
Author: User

"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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.