小白学python(001)-selenium安装与使用的那些坑

从这周开始学习自动化测试,采用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时却报错。

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值