上善若水,不进则退

姚毛毛

左手代码,右手写诗

linuxido.com

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:\Python\Python36\Scripts

  • 测试代码:打开浏览器,跳转百度,搜索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时却报错。

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

posted @ 2018-03-13 10:43  姚毛毛  阅读(756)  评论(0编辑  收藏  举报