Test12306Alert

作者在 2016-04-28 15:13:42 发布以下内容
#-*- coding:utf-8 -*-
__author__ = 'poptest'
#考察句柄,Alert弹框
from selenium import webdriver
import time

class Test12306Alert():
    def testBrowser12306(self):
        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("html/body/div[1]/div[4]/div[1]/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("html/body/div[2]/div[1]/ul/li/table/tbody/tr[1]/th/a").click()
                time.sleep(2)
        #当前窗口句柄
        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("html/body/div/div/div[6]/a[1]/span/ins").click()
        #点击下一页
        dr.find_element_by_xpath("html/body/div[2]/div[13]/input[2]").click()

        #定义弹框  alert:警告
        st = dr.switch_to_alert().text
        if st == u"请填写注册名!":
            print "same"
            #关闭弹窗,确认
            dr.switch_to_alert().accept()
        else:
            print "not same"
            dr.switch_to_alert().accept()

#类实例化
p = Test12306Alert()
#调用方法
p.testBrowser12306()
selenium2 | 阅读 2896 次
文章评论,共0条
游客请输入验证码