前言

有不少小伙伴在安装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版本也是可以的

要是觉得selenium3.0比较坑的话,可以继续用selenium2.0版本也是可以的,看这篇环境搭建:Selenium2+python自动化1-环境搭建

在安装过程中有遇到疑问和问题的,可以加selenium(python+java) QQ群交流:646645429

要是觉得对你有帮助,就在右下角点个赞吧!

selenium+python高级教程》已出书:selenium webdriver基于Python源码案例

(购买此书送对应PDF版本)

selenium3+python自动化50-环境搭建(firefox)的更多相关文章

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

    前言 有不少小伙伴在安装selenium环境后启动firefox报错,因为现在selenium升级到3.0了,跟2.0的版本还有有一点区别的. 安装环境过程中主要会遇到三个坑: 1.'geckodri ...

  2. Selenium3+python自动化006-环境搭建

    一.selenium简介 1.Selenium历史 (1)Selenium 1.0: Selenium IDE      Selenium Grid    Selenium RC(核心功能) Sele ...

  3. Appium+Python自动化 1 环境搭建(适用windows系统-Android移动端自动化)

    一.安装并配置 java jdk ①下载 java jdk后 安装,安装完成后,配置环境变量 打开计算机->系统属性->高级系统设置->环境变量->新建(系统变量),如图所示: ...

  4. Android自动化测试之环境搭建

    Android自动化测试之环境搭建 一.Android-sdk介绍 SDK(Software development kit)软件开发工具包.被软件开发工程师用于为特定的软件包.软件框架.硬件平台. ...

  5. Python+Selenium+webdriver环境搭建(windows)以及相关资源下载链接

    今天记录一下测试小菜鸟alter在测试入门的一点关于python+Selenium+webdriver环境搭建的经历以及资源分享.欢迎交流学习,批评指正. 一.Python的下载与安装 1.pytho ...

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

    Robot Framework自动化_环境搭建以及第一个脚本 培训老师:肖能尤 2016/06/07 课程目的 一.Robot framework 环境搭建以及第一个脚本 课程内容 1    安装前准 ...

  7. 基于Python的Appium环境搭建合集

    自动化一直是测试圈中的热聊,也是大家追求的技术方向.在测试中,往往回归测试也是测试人员的“痛点”.对于迭代慢.变更少的功能,就能用上自动化来替代人工回归,减轻工作量. 问题 在分享环境搭建之前,先抛出 ...

  8. python+Eclipse+pydev环境搭建

    python+Eclipse+pydev环境搭建   本文重点介绍使用Eclipse+pydev插件来写Python代码,  以及在Mac上配置Eclipse+Pydev 和Windows配置Ecli ...

  9. Python开发:环境搭建(python3、PyCharm)

    Python开发:环境搭建(python3.PyCharm) python3版本安装 PyCharm使用(完全图解(最新经典))

随机推荐

  1. WordPress用户登录后重定向到指定页面

    这篇文章将向您展示WordPress用户登录后如何重定向到指定页面或者文章的技巧. 一.重定向到网站管理面板. 将以下代码添加到您的当前主题的 functions.php 文件中: function  ...

  2. 为django平台生成模拟用户,建立用户组,并将用户加入组

    书接上篇BLOG. 当我们可以用manage.py自定义命令来生成模拟数据时, 我们面对的就是如何操作ORM的问题了. 这两天,我为我们的内部系统的所有数据表,都生成了模拟数据. 有几个心得,记录于此 ...

  3. CCF CSP 201509-4 高速公路

    CCF计算机职业资格认证考试题解系列文章为meelo原创,请务必以链接形式注明本文地址 CCF CSP 201509-4 高速公路 问题描述 某国有n个城市,为了使得城市间的交通更便利,该国国王打算在 ...

  4. Redis(二)CentOS7安装Redis4.0.10与集群搭建

    一 Redis单机安装 1 Redis下载安装 1.1 检查依赖环境(Redis是C语言开发,编译依赖gcc环境) [root@node21 redis-]$ gcc -v -bash: gcc: c ...

  5. 1497: [NOI2006]最大获利

    新的技术正冲击着手机通讯市场,对于各大运营商来说,这既是机遇,更是挑战.THU集团旗下的CS&T通讯公司在新一代通讯技术血战的前夜,需要做太多的准备工作,仅就站址选择一项,就需要完成前期市场研 ...

  6. Codeforces 429C Guess the Tree(状压DP+贪心)

    吐槽:这道题真心坑...做了一整天,我太蒻了... 题意 构造一棵 $ n $ 个节点的树,要求满足以下条件: 每个非叶子节点至少包含2个儿子: 以节点 $ i $ 为根的子树中必须包含 $ c_i ...

  7. SQL中format()函数对应的格式

    http://www.cnbeta.com/articles/tech/632057.htm

  8. 【POJ】1819.Disks

    博客园的话插链接链接都是凉的= = 题解 我理解成能不能看到这个圆,除了最后几个圆特殊以外都是等价的,然而我凉了,因为我把圆当成线段来处理,但是,有可能一个圆完全被遮住了,还有一个缝隙,就WA了 计算 ...

  9. LoadRunner脚本篇

    LoadRunner脚本篇     1概述 2脚本录制 3脚本编写 4脚本调试   关  键  词:LoadRunner 性能测试脚本 摘      要:编写一个准确无误的脚本对性能测试有至关重要的意 ...

  10. python二叉树简单实现

    二叉树简单实现: class Node: def __init__(self,item): self.item = item self.child1 = None self.child2 = None ...