selenium3+python自动化50-环境搭建(firefox)【转载】

前言

有不少小伙伴在安装selenium环境后启动firefox报错,因为现在selenium升级到3.0了,跟2.0的版本还有有一点区别的。

安装环境过程中主要会遇到三个坑:

1.‘geckodriver‘ executable needs to be in PATH

2.Expected browser binary location, but unable to find binary in default location

3.Unsupported Marionette protocol version 2, required 3

环境准备:

--python3.6

--selenium3.0

--firefox50

一、安装python

1.安装python这个简单,下载版本后傻瓜式安装就行了。

2.安装好之后,看下这个目录D:\python\Scripts,有没pip.exe和easy_install.exe(一般都有,没有的话得重新安装一次了)

3.将D:\python和D:\python\Scripts,添加到环境变量path下

二、检查pip工具

1.打开cmd,输入:pip,出现如下图界面,说明pip环境OK.

>>pip

2.要是出现异常提示:Did not provide a command,就看这篇解决:Selenium2+python自动化3-解决pip使用异常

三、安装selenium3.0

1.cmd输入:pip install selenium

>>pip install selenium

2.首次安装要看到100%完成,中途失败就重新多输入几次安装。

四、检查selenium环境

1.在cmd输入如下指令检查环境

>>python

>>from selenium import webdriver

>>driver=webdriver.Firefox()

>>driver.get("https://www.baidu.com")

2.能看到浏览器正常启动,说明环境OK,如果遇到异常就继续看下面解决方案。

五、遇到第一个坑:‘geckodriver‘ executable needs to be in PATH

1.如果启动浏览器过程中报如下错误

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\test\python3\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 145, in __init__
    self.service.start()
  File "D:\test\python3\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: ‘geckodriver‘ executable needs to be in PATH.

2.这个是因为最新的selenium3.0启动firefox需要geckodriver.exe这个驱动文件。

3.下载之后,配置到环境变量path下(可以直接放python根目录)

六、遇到第二坑:Expected browser binary location, but unable to find binary in default location

1.如果启动浏览器过程中报如下错误

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\test\python3\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 155, in __init__
    keep_alive=True)
  File "D:\test\python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 92, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "D:\test\python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 179, in start_session
    response = self.execute(Command.NEW_SESSION, capabilities)
  File "D:\test\python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 238, in execute
    self.error_handler.check_response(response)
  File "D:\test\python3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 193, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Expected browser binary location, but unable to find binary in default location, no ‘moz:firefoxOptions.binary‘ capability provided, and no binary flag set on the command line

2.这个是因为firefox.exe这个文件也需要配置到环境变量path下

3.这个路径就是安装完firefox后,找到firefox.exe这个文件的地址,加到path下

七、遇到第三坑:Unsupported Marionette protocol version 2, required 3

1.如果启动浏览器过程中出现如下错误

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\test\python3\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 155, in __init__
    keep_alive=True)
  File "D:\test\python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 92, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "D:\test\python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 179, in start_session
    response = self.execute(Command.NEW_SESSION, capabilities)
  File "D:\test\python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 238, in execute
    self.error_handler.check_response(response)
  File "D:\test\python3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 193, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Unsupported Marionette protocol version 2, required 3

2.这个错误原因是firefox版本过低了,最新的selenium3.0版本支持firefox47以上的版本,升级版本就可以了

总结:整个环境的配置是python3.6+selenium3.0+firefox47以上版本,当然python用2.7版本也是可以的

时间: 2024-08-02 16:34:41

selenium3+python自动化50-环境搭建(firefox)【转载】的相关文章

selenium3+python自动化50-环境搭建(firefox)

前言 有不少小伙伴在安装selenium环境后启动firefox报错,因为现在selenium升级到3.0了,跟2.0的版本还有有一点区别的. 安装环境过程中主要会遇到三个坑: 1.'geckodriver' executable needs to be in PATH 2.Expected browser binary location, but unable to find binary in default location 3.Unsupported Marionette protoco

基于Python的Appium环境搭建合集

自动化一直是测试圈中的热聊,也是大家追求的技术方向.在测试中,往往回归测试也是测试人员的“痛点”.对于迭代慢.变更少的功能,就能用上自动化来替代人工回归,减轻工作量. 问题 在分享环境搭建之前,先抛出我的一个疑问吧. app启用时,分不同的场景: 1.首次安装启用,有欢迎页: 2.非首次启用,直接进入到登录页: 3.配置了推荐展示时,启用app,会先展示推荐内容,才进入到登录页. 不同场景对应的activity都是不同的,我目前处理办法是,写了个输入函数,加了个if判断去对应不同的activit

Android自动化测试之环境搭建

Android自动化测试之环境搭建 一.Android-sdk介绍? SDK(Software development kit)软件开发工具包.被软件开发工程师用于为特定的软件包.软件框架.硬件平台.操作系统等建立应用软件的开发工具的集合.Android是google公司推出的手机开发平台.Android-sdk就是指Android专属的软件开发工具包. Android-sdk中我们最常用的就是tools和Platformtools文件夹中的工具. 二.工具安装? 1.android-sdk只需

Robot Framework自动化_环境搭建以及第一个用例

Robot Framework自动化_环境搭建以及第一个脚本 培训老师:肖能尤 2016/06/07 课程目的 一.Robot framework 环境搭建以及第一个脚本 课程内容 1    安装前准备工作 搭建环境所需要的安装文件已经下载好,从SVN上获取即可,解压,如下 2   Robotframework环境搭建 2.1  安装Python 官网下载地址: http://www.python.org/getit/ 2.2  安装setuptools-15.1 2.3  安装pip 2.4 

萌新向Python数据分析及数据挖掘 第一章 Python基础 第一节 python安装以及环境搭建 第二节 变量和简单的数据类型

本文将参考<Python编程 从入门到实践>的讲述顺序和例子,加上自己的理解,让大家快速了解Python的基础用法,并将拓展内容的链接添加在相关内容之后,方便大家阅读. 好了!我们开始第一章的学习. 第一章 Python基础 第一节 Python安装以及环境搭建 Python的安装和环境变量的配置通过百度查询即可解决,这里不作赘述. IDE的选择:因为后期需要用来做数据分析,所以直接安装Anaconda会是一个不错的选择. Anaconda详细安装使用教程 https://blog.csdn.

Python + Selenium 环境搭建

Python + Selenium 环境搭建 注:本文是根据网上资料收集验证整理而得,仅供学习 准备如下: 1.下载 python http://python.org/getit/ 2.下载 setuptools http://pypi.python.org/pypi/setuptools 3.下载 pip https://pypi.python.org/pypi/pip setuptools 是 python 的基础包工具,可以帮助我们轻松的下载,构建,安装,升级,卸载 python的软件包.

python(pyqt)开发环境搭建

eric+pyqt 安装(python开发工具) 更多 0 Python python Eric是一个开源的.跨平台的python&ruby集成开发环境,基于python和pyqt运行.eric有以下特点 1.跨Windows/Linux/Mac等开台 2.调试器给力.支持设置断点,单步调试,查看变量值. 3.支持工程. 4.支持自动补全. 5.支持智能感知,即输入变量名和一个点,会自动提示可能的函数. 6.自动语法检查.每次保存时自动检查. 7.支持自动缩进,会自动判断if, while等语句

《Python入门》Linux 下 Python Web开发环境搭建笔记

之前写过 Windows 7下Python Web开发环境搭建笔记,今天写一下在Linux系统下搭建Python Web的开发测试环境. 我使用的系统是:ubuntu 14.04 server,根据个人经验,CentOS 6.5 下也适用. 关于Python的版本 进入Python的网站,鼠标移到导航条上的下载,我们会发现提供两下主版本的下载链接! 这两个之间存在什么差别呢? 个人理解,2.7.x的版本为更加稳定的版本,而3.x的版本则是比较前卫的版本,包含了很多新功能新特性之类的: 但如果想要

Python基础(1)python+Eclipse+pydev环境搭建

编辑器:Python 自带的 IDLEPython基础(1)python+Eclipse+pydev环境搭建