1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > Web自动化测试工具——selenium

Web自动化测试工具——selenium

时间:2018-12-29 08:08:10

相关推荐

Web自动化测试工具——selenium

一、特点

1、开源、免费

2、跨平台Linux、Windows、Mac

3、支持多浏览器

4、支持多种语言:java、python···

二、selenium

1、安装:

安装方法一: 通过pip包管理工具安装:

安装:pip install selenium

查看:pip show selenium

卸载:pip uninstall selenium

安装指定的版本号的selenium:pip install selenium==版本号

查看指定版本号:可以通过安装错误的版本号,从而获取提示

注:

1.使用pip指令时全部都是以管理员的身份打开cmd,如果出现报错:You are using pip version 18.1, however version 22.2 is available. 解决方法:

方法1:可以直接在命令行中输入(不要使用家里的WiFi,连接使用手机热点),来升级pip:

python -m pip install --upgrade pip

方法2:使用镜像下载升级pip:

python -m pip install --upgrade pip -i /simple

安装方法二:在PyCharm中针对当前工程进行安装环境(常用)

步骤①:

步骤②:

步骤③:

2.pip 是python中包管理工具(可以安装、卸载、查看python工具),默认安装python3.5版本以上工具,自带pip包管理工具,默认会自动安装并且添加path环境变量。同时,使用pip时必须要联网。

2.浏览器及驱动安装

浏览器:火狐

驱动:

1.火狐:Releases · mozilla/geckodriver · GitHub

2.谷歌:/a//chromedriver/downloads

3.IE:Microsoft Edge WebDriver - Microsoft Edge Developer

浏览器驱动下载后复制在python的根路径下以及响应的浏览器的Application目录下,然后配置环境变量path,才能成功。

步骤:

下载与你本身的浏览器版本相对应的浏览器驱动(否则在后面就会出现driver = webdriver.Chrome()错误),再加载后的浏览器驱动复制在python的根路径下以及响应的浏览器的Application目录下:

再将python根目录下的浏览器驱动的路径写在环境变量path中即可:

案例演示:

from time import sleepfrom selenium import webdriverdriver = webdriver.Chrome()driver.get('')sleep()driver.quit()

上面代码运行出现错误:

Traceback (most recent call last):File "D:\Program Files\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 74, in startstdout=self.log_file, stderr=self.log_file)File "D:\Program Files\Python35\lib\subprocess.py", line 947, in __init__restore_signals, start_new_session)File "D:\Program Files\Python35\lib\subprocess.py", line 1224, in _execute_childstartupinfo)FileNotFoundError: [WinError 2] 系统找不到指定的文件。During handling of the above exception, another exception occurred:Traceback (most recent call last):File "C:\Users\Administrator\Desktop\count.py", line 3, in <module>driver = webdriver.Firefox()File "D:\Program Files\Python35\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 145, in __init__self.service.start()File "D:\Program Files\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 81, in startos.path.basename(self.path), self.start_error_message)mon.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

问题解决:出现mon.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 错误的原因就是浏览器驱动的环境配置有问题,注意严格按照上面的要求进行。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。