8、12306diaochawenjvan

作者在 2016-04-03 17:09:56 发布以下内容
 
#-*- coding:utf-8 -*-
__author__ = 'poptest'
#考察句柄
from selenium import webdriver
import time
import sys

def main():
    #打开火狐浏览器
    dr= webdriver.Firefox()
    #窗口最大化
    dr.maximize_window()
    #输入12306网址
    dr.get("http://www.12306.cn/mormhweb/")
    # 定义当前窗口句柄1
    cuhandle = dr.current_window_handle

    #点击旅客服务质量调查问卷
    dr.find_element_by_xpath(".//*[@id='newLeft']/div[3]/a/img").click()
    time.sleep(2)
    #所有打开窗口句柄
    allhandle = dr.window_handles

    for i in allhandle:
        if i != cuhandle:
            #转换到第i个窗口
            dr.switch_to_window(i)
            dr.find_element_by_xpath(".//*[@id='classfied1']/ul/li/table/tbody/tr[1]/th/a").click()
            time.sleep(2)
            #sys.exit
    #当前窗口句柄
    n = dr.current_window_handle
    allhandle = dr.window_handles
    for n in allhandle:

        if n != cuhandle and n != i:
            dr.switch_to_window(n)
            time.sleep(2)

            #我已阅读并同意
            dr.find_element_by_xpath(".//*[@id='agree']/span/ins").click()
            dr.find_element_by_xpath(".//*[@id='close']").click()

            dr.quit()
main()
selenium | 阅读 11312 次
文章评论,共0条
游客请输入验证码