zoukankan      html  css  js  c++  java
  • selenium2自动化测试学习笔记(一)

    从这周开始学习自动化测试,采用selenium2,目标是在本月学习到appium,并测试公司的真实APP项目。

    系统环境:win10

    语言:python3.6.4

    工具:selenium2

    IDE:python IDLE

    浏览器(需下载相对应的webdriver):

    IE11

    Chrome65.0.3325.146

    Firefox58

    • Windows下载安装python

    基础书籍是虫师的selenium2自动化测试实战(基于python语言)。

    下载了python3.6.4,https://www.python.org/

    在安装python的时候一定要自定义,然后选择add path,否则需要手工添加环境变量

    安装好后,打开cmd,输入 python,显示版本情况,说明安装成功。

    python3.6.4已经默认安装了pip,在cmd中使用pip install selenium安装selenium。

    • webdriver驱动下载

    原文链接:https://www.cnblogs.com/feiquan/p/8531686.html

    IE11的Webdriver下载:

      http://dl.pconline.com.cn/download/771640-1.html

      链接:https://pan.baidu.com/s/13TTyXGNaG5cpSNdl1k9ksQ 密码:2n9n

    Chrome65.0.3325.146的webdriver驱动下载:

      链接:https://pan.baidu.com/s/1gv-ATOv_XdaUEThQd5-QtA 密码:dzh2

      多版本:http://chromedriver.storage.googleapis.com/index.html

    Firefox58的webdriver驱动下载

      链接:https://pan.baidu.com/s/1RATs8y-9Vige0IxcKdn83w 密码:l41g

    将驱动放到安装目录下的scripts文件夹下,我的路径是C:PythonPython36Scripts

    • 测试代码:打开浏览器,跳转百度,搜索selenium2
    # conding=unicode
    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    import sys
    
    #加载
    #driver = webdriver.Firefox()
    driver = webdriver.Chrome()
    #driver = webdriver.Ie()
    
    #打开百度
    driver.get("http://www.baidu.com")
    
    #搜索Selenium2
    
    
    try:
        kw = driver.find_element_by_id("kw")
        su = driver.find_element_by_id("su")
       
    except:
        print ('element does not exist')
    
    print("kw is " , kw.is_enabled() ) #判断元素是否有效
    
    assert "百度" in driver.title
    kw.send_keys('selenium2')
    
    su.click()
    
    #退出
    #driver.quit()
    • geckodriver

    使用以上代码,火狐毫无问题

    • IEDriverServer 报错

    driver = webdriver.Ie()
    driver.get("http://www.baidu.com")
    以上代码报This is the initial start page for the WebDriver server
    解决方法:将ie浏览器安全下所有选项的“启动保护模式”全部不勾选

    接着又碰到一个错误:Unexpected error launching Internet Explorer. Browser zoom level was set to 200%. It should be set to 100%

    调整IE右下角的缩放比就好了,回到100%才行,真坑

    解决方案原文:http://blog.csdn.net/funi16/article/details/9036753

    以上问题解决后,接下去的代码正常打开,无问题

    • chromeDriver 报错

    使用以上代码只能打开百度窗口,但是在kw.send_keys时却报错。

    至今没有解决。不知道有没有人遇到,无语了。

    作者:妖生
    <<<<我的公众号:姚毛毛的博客
    Linux常用工具站:https://www.linuxido.com
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
    如果喜欢本文就点个【推荐】吧。
  • 相关阅读:
    2019-05-07
    2019-04-28 问题记录
    2019-04-15 python深浅复制
    2019-04-11 统计日志重复数量
    2019-03-23 shell练习,日志统计
    问题记录2019-03-12
    问题记录2019-03-06(todo)
    回归
    Mac进行 usr/bin 目录下修改权限问题,operation not permitted
    个人的随笔心情
  • 原文地址:https://www.cnblogs.com/yaomaomao/p/8554694.html
Copyright © 2011-2022 走看看