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