• Selenium 2自动化测试实战12(获得验证信息)


    一、获得验证信息


    通常用的最多的几种验证信息分别是:title、URL和text

    运行脚本之后,结果如下图所示:

    #coding:utf-8
    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    import time
    
    driver=webdriver.Chrome()
    driver.get("https://xui.ptlogin2.qq.com/cgi-bin/xlogin?target=self&appid=522005705&daid=4&s_url=https://mail.qq.com/cgi-bin/readtemplate?check=false%26t=loginpage_new_jump%26vt=passport%26vm=wpt%26ft=loginpage%26target=&style=25&low_login=1&proxy_url=https://mail.qq.com/proxy.html&need_qr=0&hide_border=1&border_radius=0&self_regurl=http://zc.qq.com/chs/index.html?type=1&app_id=11005?t=regist&pt_feedback_link=http://support.qq.com/discuss/350_1.shtml&css=https://res.mail.qq.com/zh_CN/htmledition/style/ptlogin_input_for_xmail440503.css")
    print("Before login======================")
    
    #打印当前页面title
    title=driver.title
    print title
    
    #打印当前页面URL
    now_url=driver.current_url
    print now_url
    
    #执行邮箱登录
    driver.find_element_by_id("switcher_plogin").click()
    time.sleep(1)
    driver.find_element_by_id("u").send_keys("username")
    driver.find_element_by_id("p").send_keys("password")
    time.sleep(2)
    driver.find_element_by_id("p").send_keys(Keys.ENTER)
    time.sleep(5)
    
    print ('After login==================')
    
    #再次打印当前页面title
    title=driver.title
    print title
    
    #打印当前页面URL
    now_url=driver.current_url
    print now_url
    
    #获得登录的用户名
    user=driver.find_element_by_id("useralias").text
    print user
    
    driver.quit()  

    title:用于获得当前页面的标题
    current_url:用户获得当前页面的URL

    通过此例得知,发现登录前后的title和URL明显不同。因此通过text获取用户文本是很好的验证信息。

  • 相关阅读:
    SpringData概述
    运行javac 报告javac不是内部或外部命令,但是运行java、java-version正常
    Spring Data JPA
    spring-data-jpa 介绍 复杂查询,包括多表关联,分页,排序等
    Thymeleaf使用说明
    Specifications查询
    OA项目_环境搭建
    anu
    anu
    anu
  • 原文地址:https://www.cnblogs.com/Rita-LJ/p/11544003.html
Copyright © 2020-2023  润新知