日期控件
1.直接输入
2.没有办法直接输入的 执行js脚本方法
js语句a = document.getElementById("train_date")查找元素,a.value = "2018-11-01修改默认值
多用在 评论框和日历
示例12306 查票日期
'''
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time
from selenium import webdriver
driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://kyfw.12306.cn/otn/index/init")
#js语句准备
# js_pha='var a = document.getElementById("train_date");a.removeAttribute("readonly");'
# time.sleep(2)
# #执行js
# driver.execute_script(js_pha)
# driver.find_element_by_xpath('//div[@class="inp-w"]//input[@readonly="readonly"]').send_keys("2018-11-01")
#js语句a = document.getElementById("train_date")查找元素,a.value = "2018-11-01修改默认值
js_pha='a = document.getElementById("train_date");a.value = "2018-11-01";'
driver.execute_script(js_pha)
js_cf='a =document.getElementById("fromStationText");a.value = "北京";'
driver.execute_script(js_cf)
js_md='a =document.getElementById("toStationText");a.value = "安阳";'
driver.execute_script(js_md)
# cf=driver.find_element_by_id('fromStationText')
# cf.clear()
# cf.send_keys('北京')
# md = driver.find_element_by_id('toStationText').send_keys('安阳')
# md.clear()
# md.send_keys('安阳')
#点击查询
driver.find_element_by_id('a_search_ticket').click()