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

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

前言

有不少小伙伴在安装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:pythonScripts,有没pip.exe和easy_install.exe(一般都有,没有的话得重新安装一次了)

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

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

二、检查pip工具

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

>>pip

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

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

三、安装selenium3.0

1.cmd输入:pip install selenium

>>pip install selenium

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

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

四、检查selenium环境

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

>>python

>>from selenium import webdriver

>>driver=webdriver.Firefox()

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

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

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

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

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

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D: estpython3libsite-packagesseleniumwebdriverfirefoxwebdriver.py", line 145, in __init__
self.service.start()
File "D: estpython3libsite-packagesseleniumwebdrivercommonservice.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: estpython3libsite-packagesseleniumwebdriverfirefoxwebdriver.py", line 155, in __init__
keep_alive=True)
File "D: estpython3libsite-packagesseleniumwebdriver emotewebdriver.py", line 92, in __init__
self.start_session(desired_capabilities, browser_profile)
File "D: estpython3libsite-packagesseleniumwebdriver emotewebdriver.py", line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "D: estpython3libsite-packagesseleniumwebdriver emotewebdriver.py", line 238, in execute
self.error_handler.check_response(response)
File "D: estpython3libsite-packagesseleniumwebdriver emoteerrorhandler.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下

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

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

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

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D: estpython3libsite-packagesseleniumwebdriverfirefoxwebdriver.py", line 155, in __init__
keep_alive=True)
File "D: estpython3libsite-packagesseleniumwebdriver emotewebdriver.py", line 92, in __init__
self.start_session(desired_capabilities, browser_profile)
File "D: estpython3libsite-packagesseleniumwebdriver emotewebdriver.py", line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "D: estpython3libsite-packagesseleniumwebdriver emotewebdriver.py", line 238, in execute
self.error_handler.check_response(response)
File "D: estpython3libsite-packagesseleniumwebdriver emoteerrorhandler.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以上的版本,升级版本就可以了

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

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

免责声明:文章转载自《selenium3+python自动化50-环境搭建(firefox)【转载】》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇设置 centos 系统,使用终端连接的空闲等待时间(超时断开)Redis实现之压缩列表下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

postman 断言学习

请求 url :https://www.v2ex.com/api/nodes/show.json?name=python get请求 postman发起请求并做断言 断言: tests["Body matches string"] = responseBody.has("这里讨论各种 Python 语言编程话题,也包括 Django,Tornado 等框...

Python,environ解惑

最近又遇到了对环境变量读取的问题,以前的学习很快会忘记~ 还是写篇博客稍微记录下比较好 首先我们都应该知道在平常的开发中我们经常会配置一些系统环境变量。 不论是windows系统或者是linux系统,比如: # Windows set test=123 # Linux export test=123 再而我们在进行web开发的时候也会遇到各种,变量的控...

Python灰帽子--黑客与逆向工程师的Python编程之道 笔记,过程问题解决

↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑电脑端的可以看看目录 跟着学习进度不断更新中。。。。(因为懒,没更新了,也不打算继续更新文章了......) power by 《python灰帽子--黑客与逆向工程师的Python编程之道》 欢迎光顾我的新博客:https://www.giantbranch.cn 本文链接:http://bl...

python实现注册登录小程序

用python 实现模拟注册和登录的程序:用户信息最终以字典的格式储存在一个txt文件里,具体实现如下: users.txt里用户字典格式如下: 1 { 2 'name': {'password': '111111', 'role': '1'}, 3 'name2': {'password': '222222', 'role': '1'},...

我与Python惺惺相惜

while循环 死循环,会一直一直的重复循环.True的首字母要大写. while True: print("我与世界格格不入,我只与你惺惺相惜") count = 1 while count <=5: print("我与世界各格格不入,我只与你惺惺相惜") count = count + 1 解析: count=1,进行判断1小于等于5条件成立...

使用python爬虫爬取股票数据

前言: 编写一个爬虫脚本,用于爬取东方财富网的上海股票代码,并通过爬取百度股票的单个股票数据,将所有上海股票数据爬取下来并保存到本地文件中 系统环境: 64位win10系统,64位python3.6,IDE位pycharm 预备知识: BeautifulSoup的基本知识,re正则表达式的基本知识 代码: importrequests from bs4 i...