ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

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

2021-09-16 16:33:19  阅读:135  来源: 互联网

标签:python Selenium driver Python 自动化 pip 安装 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

标签:python,Selenium,driver,Python,自动化,pip,安装,Python3,selenium
来源: https://www.cnblogs.com/chenxiaomeng/p/15294085.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有