Python3+Selenium自动化测试安装以及各种踩坑

Python3+Selenium自动化测试安装
1.python安装
python官网地址https://www.python.org/
在Windows上安装python,我下载的是64位安装程序
特别要注意勾上“Add Python 3.8 to PATH”,然后点“install now”即可完成安装

2.Selenium安装
使用python可直接利用pip进行安装selenium
启动cmd,注意:需要以管理员身份运行
Pip install -U selenium

测试驱动driver安装
Google Chrome driver:https://sites.google.com/a/chromium.org/chromedriver/downloads
我用的是谷歌浏览器,下载下来的zip文件解压至谷歌浏览器安装目录中

测试驱动driver测试

CMD中启动python并从selenium引入webdriver包:
from selenium import webdriver

驱动chrome浏览器
(1)Ch_driver = webdriver.Chrome()
(2)Ch_driver.get(“https://www.google.com”)
(3)Ch_driver.quit() # 使用quit()关闭了chrome并结束了此次测试,如果是close()只是关闭chrome,后台仍在进行。

踩坑
python执行pip install 命令的时候出现 File"",line 1 pip install 的问题
原因:pip是Python 包管理工具,该工具提供了对Python包的查找,下载,安装,卸载的功能,是直接在cmd中运行的,不需要进入到python中运行
解决方法:关掉当前cmd窗口,重新进入,不需要进入python,直接输入pip命令即可

解决 FileNotFoundError: [WinError 2] 系统找不到指定的文件

Ch_driver = webdriver.Chrome()
Traceback (most recent call last):
  File "C:\Users\TESTING-PC\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "C:\Users\TESTING-PC\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\TESTING-PC\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 1307, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] 系统找不到指定的文件。

根据提示找到lib中的subprocess.py文件,CTRL+f查找class Popen模块,再将这个模块中的
__init__函数中的shell = False 改成shell = True

This version of ChromeDriver only supports Chrome version 78
这是因为与本地谷歌浏览器版本不对应,再重新下载另一个版本的chromedriver. 所有的chromedriver均可在下面链接中下载到:http://chromedriver.storage.googleapis.com/index.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值