Selenium2+python Automation 25-js Process Calendar Control (Modify ReadOnly property) "Reprint"

Source: Internet
Author: User
Tags ticket

Objective

Calendar control is a Web site often encounter a scene, some input boxes can be directly entered the date, some cannot, with our frequent ticket to the 12306 site as an example, detailed how to solve the Calendar control for the ReadOnly property problem.

Basic idea: First use JS to remove the ReadOnly attribute, and then directly enter the date text content

One, Calendar control

1. Open the 12306 ticket query interface, cannot enter the time directly in the Departure date input box

2. The general idea is to open the Calendar control pop-up box, from the Calendar control point date, so the operation is more irritable, and we test the focus is not on the calendar control, just want to enter a time, do the next action

3. Use Firebug to view the properties of the input box: readonly= "readonly", as follows:

<InputId= "Train_date "Class= "inp-txt "  type= "text"  value= " "  Name= "leftticketdto.train_date"  autocomplete= "off"  maxlength= " 10 "  readonly= "readonly" >

Second, remove the ReadOnly attribute

1. It is obvious that the attribute of this element is readonly, the input box cannot be entered directly, it is necessary to remove the element's ReadOnly attribute, then you can enter it.

2. Click the "Edit button" in the lower left corner of the Firebug to find the corresponding element and delete it directly. readonly= "readonly" and then enter.

3. On the page departure date location input: Yoyoketang Try, hey, there is no discovery can enter success. Of course, this is just to verify that you can enter the content, and the test date when you enter the test.

Third, use JS to remove the ReadOnly attribute

1. Use JS to remove the basic idea of element attributes: first locate the element and then delete the attribute with the RemoveAttribute ("ReadOnly") method.

2. Departure Yen Vegetarian ID: train_date, corresponding JS code: ' document.getElementById ("Train_date"). RemoveAttribute ("readonly"); '

Iv. Input Date

1. Before entering the date, be sure to clear the text first, or you will not be able to enter a successful.

2. Enter the date here, will automatically pop up the Calendar control, casually click on the other location is good, next will use the JS method in the date, will not play!

Five, JS method input Date

1. You can also use the JS method to enter the date, in fact, it is very simple, directly change the value of the input box element can be

Six, the reference code is as follows:

# Coding:utf-8
From selenium import Webdriver
Driver = Webdriver. Firefox ()
Driver.get ("Https://kyfw.12306.cn/otn/index/init")
# Remove the ReadOnly attribute of the element
JS = ' document.getElementById ("Train_date"). RemoveAttribute ("readonly"); '
Driver.execute_script (JS)

# Enter the date with the JS method
Js_value = ' document.getElementById ("Train_date"). Value= "2016-12-25"
Driver.execute_script (Js_value)

# # Enter values after emptying text
# driver.find_element_by_id ("Train_date"). Clear ()
# driver.find_element_by_id ("Train_date"). Send_keys ("2016-12-25")

Selenium2+python Automation 25-js Process Calendar Control (Modify ReadOnly property) "Reprint"

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.