Selenium+python Automatic Processing Time control

Source: Internet
Author: User

When trying to write an automated script that queries the 12306 Web site for the rest of the ticket information, the problem of date selection is encountered here:

Originally intended to direct positioning, but found that the 2017-09-30 day is really no feature, although it can also be based on the characteristics of the parent element layer layer positioning, and then select the number of child under the child element, but there is a problem, after a day, the child element is not number 30th, and the original intention, So online to find the solution, see there is said to get rid of the time frame of the ReadOnly attribute, directly with the input method is solved with Send_keys, all encountered time choice, can be resolved by this way, deep thought, and then tried, sure enough, here to write down the method:

Method one: Native JS, remove ReadOnly Property

JS = "document.getElementById (' train_date '). RemoveAttribute (' readonly ')"

Method Two: JQuery, removing the readonly attribute

JS = "$ (' input[id=train_date] '). Removeattr (' readonly ')"

Method Three: JQuery, set property to False

JS = "$ (' input[id=train_date] '). attr (' readonly ', False)"

Method Four: JQuery, set property to null

JS = "$ (' input[id=train_date] '). attr (' readonly ', ')"

And then

Driver.execute_script (JS)
driver.find_element_by_id (' train_date '). Clear ()
driver.find_element_by_id ('train_date '). Send_keys (' 2017-09-30 ')

问题解决!

Note: This article refers to the Huilan_same CSDN blog, but the author has actually tried, it is feasible, thank Huilan_same to provide the method.

Original address: http://blog.csdn.net/huilan_same/article/details/52385401

Selenium+python Automatic Processing Time control

Related Article

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.