7、12306wangfanchaxun

作者在 2016-04-03 16:56:49 发布以下内容
#-*- coding:utf-8 -*-
__author__ = 'poptest'
#考察去掉只读属性
import time
from  selenium import webdriver
def main():
    #打开火狐浏览器
    dr = webdriver.Firefox()
    #窗口最大化
    dr.maximize_window()
    #输入往返地址
    dr.get("https://kyfw.12306.cn/otn/leftTicket/init")

    #点击往返
    dr.find_element_by_xpath(".//*[@id='wf']").click()
    #点击出发地下拉菜单
    dr.find_element_by_xpath(".//*[@id='fromStation_icon_image']").click()
    #单击目标出发地栏
    dr.find_element_by_xpath(".//*[@id='nav_list5']").click()
    time.sleep(1)
    #点击下一页
    dr.find_element_by_xpath(".//*[@id='flip_cities2']/a").click()
    time.sleep(1)
    #点击目的地
    dr.find_element_by_xpath(".//*[@id='ul_list5']/li[28]").click()
    time.sleep(1)

    #点击目的地文本框
    dr.find_element_by_xpath(".//*[@id='toStationText']").click()
    time.sleep(1)
    #选择目的地北京
    dr.find_element_by_xpath(".//*[@id='ul_list1']/li[1]").click()
    time.sleep(1)

    #修改属性值,去掉只读属性
    str = "document.getElementById('train_date').readonly=false"
    # 把预定日期填进去
    strdate = "document.getElementById('train_date').value=\'2016-04-10\'"
    #执行非只读属性
    dr.execute_script(str)
    #把指定日期写进去
    dr.execute_script(strdate)
    #同上
    str1 = "document.getElementById('back_train_date').readonly=false"
    strdate1 = "document.getElementById('back_train_date').value=\'2016-04-12\'"
    dr.execute_script(str1)
    dr.execute_script(strdate1)
    time.sleep(2)

    #点击查询
    dr.find_element_by_id("query_ticket").click()
main()

selenium | 阅读 10947 次
文章评论,共0条
游客请输入验证码