1.6 selenium3+firefox环境搭建

有不少小伙伴在安装selenium环境后启动firefox报错,因为现在selenium升级到3.0了,跟2.0的版本还有有一点区别的。
(备注:这里不建议大家用selenium3,坑太多,如果selenium2实在用不了,那就看这篇吧)
安装环境过程中主要会遇到三个坑:
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

三、安装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版本也是可以的。

1.6 selenium3+firefox环境搭建的更多相关文章

  1. python3+ selenium3开发环境搭建-手把手教你安装python(详细)

    环境搭建 基于python3和selenium3做自动化测试,俗话说:工欲善其事必先利其器:没有金刚钻就不揽那瓷器活,磨刀不误砍柴工,因此你必须会搭建基本的开发环境,掌握python基本的语法和一个I ...

  2. python3+ selenium3开发环境搭建

    环境搭建 基于python3和selenium3做自动化测试,俗话说:工欲善其事必先利其器:没有金刚钻就不揽那瓷器活,磨刀不误砍柴工,因此你必须会搭建基本的开发环境,掌握python基本的语法和一个I ...

  3. Selenium3+Python3环境搭建

    安装python 官网直接下载当前最新版的python Python官网地址:https://www.python.org/ 百度搜索Python3.6安装步骤 Python安装步骤:自行百度,暂不提 ...

  4. ununtu16.04+python3+selenium+firefox环境搭建

    一.初始配置: 1.安装完系统并配置好地址及DNS.2.设置root密码: sudo passwd root 3.更改云源: sudo cp /etc/apt/sources.list /etc/ap ...

  5. python+selenium自动化软件测试(第1章):环境搭建,你也可以直接用Anaconda!

    1.1 环境搭建 1.1.1 selenium简介Selenium 是用于测试 Web 应用程序用户界面 (UI) 的常用框架.它是一款用于运行端到端功能测试的超强工具.您可以使用多个编程语言编写测试 ...

  6. selenium3+python3+Firefox54环境搭建

    之前使用的环境:selenium2.53.6+Firefox44+Python2.7,没有问题,最近想尝试一下新的环境,就搭了个selenium3的环境,过程是挺坎坷的,花费了一天的时间,各种报错,最 ...

  7. Web自动化测试环境搭建1(基于firefox火狐浏览器)

    自动化测试是时代趋势,因此很多测试人员开始研究自动化测试,web自动化测试化测试并不难,但是很多人都是被挡在了环境搭建这一步,后面学习激情全无,这里,韬哥手把手教大家搭建火狐浏览器下的自动化测试环境( ...

  8. Python3+selenium3环境搭建笔记

    系统:win7 64位浏览器:ie9 64位 chrome70 32位 firefox63 64位python版本:3.6.5 Windows x86 executable installersele ...

  9. 测试自动化:java+selenium3 UI自动化(1) - 环境搭建

    1.前言 我大概是在2012年第一次正式接触到自动化测试,那个时候跟随我的团队一起,就当时项目的UI自动化尝试做出了探索. 在我离开那家公司的时候,我们的自动化测试体系仍然难言完美,但是也已经达到了非 ...

随机推荐

  1. mysql获取随机字符串和随机数的方法

    在我们开发的过程中,我们可能会需要在表中随机生成一些数据以供我们进行相应的测试. 就像我之前发的“mysql创建存储过程向数据表中加入规定条数的数据” 那么我们应该怎样生成随机的字符串和随机数字呢? ...

  2. WDCP面板Web环境安装redis与phpredis扩展应用方法

    http://www.ctyun.cn/bbs/thread-2882-1-1.html根据网友的要求需要在WDCP面板环境中安装人人商城程序,但是这个程序需要支持redis与phpredis扩展.根 ...

  3. Luogu P1010 幂次方

    [橙题不会做系列]QAQ 是李老师上课的题目-- 这题最开始想法是打表做.事实证明这样做也可以( 老师用的是位运算-- 这种一步步分解也能想到用递归qwq #include <algorithm ...

  4. Python sqlalchemy orm 多对多外键关联

    多对多外键关联 注:使用三张表进行对应关联 实现代码: # 创建3个表 配置外键关联 # 调用Column创建字段 加类型 from sqlalchemy import Table, Column, ...

  5. 尚硅谷面试第一季-17Redis 在项目中的使用场景

    数据类型 使用场景 String 比如说 ,我想知道什么时候封锁一个IP地址.Incrby命令 Hash 存储用户信息[id,name,age] Hset(key,field,value) Hset( ...

  6. 批量操作RunTime之获取的Dic换成Model

    方法一: // // AlinkDeviceInfo.m //// // Created by Vivien on 2018/10/12. // Copyright © 2018年 . All rig ...

  7. SpringBoot整合shiro实现用户的认证授权

    * 项目环境搭建 * 配置ShiroConfig,用于shiro的基本配置和注入自定义规则 * 实现自定义的realm,继承AuthorizingRealm * 编写测试controller和页面 基 ...

  8. oracle 老用户数据导入新建用户

    $sqlplus/nolog       #使用PLSQL进入oracleSQL>conn/as sysdba #进入sysdba权限CREATE DIRECTORY datadir1 AS ' ...

  9. Lintcode481-Binary Tree Leaf Sum-Easy

    481. Binary Tree Leaf Sum Given a binary tree, calculate the sum of leaves. Example Example 1: Input ...

  10. C#中get和set

    释一: 属性的访问器包含与获取(读取或计算)或设置(写)属性有关的可执行语句.访问器声明可以包含 get 访问器或 set 访问器,或者两者均包含.声明采用下列形式之一: get {} set {} ...