selenium3.0不兼容火狐的解决方案
当直接调用火狐出现不兼容错误时,如何解决?
详看Message中提示:Expected browser binary location,but unable to find binary in default location,大概意思就是说寻找不到binary。
总的结果来说,selenium3.0不支持firefox默认的driver了,但是在selenium2.x版本是可以支持的,这就是差异,
到http://www.assertselenium.com/selenium-3/firefoxdriver-in-selenium-3/地址我们可以获取到我们想要的信息
依据如上的信息,可以看到,selenium3.0在firefox浏览器中提供了GeckDriver,需要使用它,也就是说之前的默认自带的driver在selenium30.已经不能使用了,需要使用GeckDriver,GeckDriver代替了之前的自带默认的driver,这样的好处是每个浏览器都可以自己开发driver,来适配selenium3.0来进行自动化的测试,接着继续往下看,可以看到,提供了GeckDriver的下载地址,见原文
---------------------------------------------------------------------------------------------------------------------
以上为分析废话,具体步骤如下:
①下载GeckDriver https://github.com/mozilla/geckodriver/releases
记住根据自己电脑的环境来下载哦
② 把GeckDriver在该地址下载后,解压得到geckodriver.exe文件,把它加入到环境变量 (如我放在之前设置好的环境变量目录 c:\python35)
③ 接着想使用GeckoDriver ,firefox浏览器必须是48或者更高版本。于是升级firefox,保障浏览器版本在48或者更高
④ 升级后,把binary加入进去,就可以正常的运行了,见执行的源码:
# -*- coding:utf-8 -*- from selenium import webdriver #导入webdriver包
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary #导入friefox webdriver 包
import time #调入time函数 binary = FirefoxBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe") #加入Firefox的路径
driver =webdriver.Firefox(firefox_binary=binary) #### 定义driver 要操控火狐浏览器 webdriver.firefox driver.get("http://www.baidu.com")
time.sleep(0.3) #休眠0.3秒
driver.find_element_by_id("kw").send_keys("selenium")
####一个控件有若干属性id 、name、(也可以用其它方式定位),百度输入框的id 叫kw 我要在输入框里输入 selenium 。
driver.find_element_by_id("su").click()
####搜索的按钮的id 叫su ,我需要点一下按钮( click() )。
time.sleep(3) # 休眠3秒
print(driver.title) # 把页面title 打印出来 当没看到整个脚本执行过程时,看到打印出这句话,就说明页面被正确打开了
driver.quit() #退出并关闭窗口的每一个相关的驱动程序 类似的表弟为 driver.close()
# driver.close() #关闭当前窗口
------------------分析一下------------------------------
1.增加多了一句 from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
2.增加Firefox的路径
3.原来的直接调用driver=webdriver.firefox() 变成了 driver =webdriver.Firefox(firefox_binary=binary)

好了,解决掉以上问题 配置环境调用浏览器问题应该就完全解决了吧。
selenium3.0不兼容火狐的解决方案的更多相关文章
- 1 selenium3.0.1无法打开火狐浏览器
[问题描述] 1.配置selenium3.0和java后,尝试打开火狐浏览器,提示缺少geckodriver驱动. [解决方案] 1.在http://www.seleniumhq.org/downlo ...
- 【基础】火狐和谷歌在Selenium3.0上的启动(二)
参考地址:http://www.cnblogs.com/fnng/p/5932224.html https://github.com/mozilla/geckodriver [火狐浏览器] 火狐浏览器 ...
- css把超出的部分显示为省略号的方法兼容火狐
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...
- Selenium2+python自动化2-pip降级selenium3.0
selenium版本安装后启动Firefox出现异常:'geckodriver' executable needs to be in PATH selenium默默的升级到了3.0,然而网上的教程都是 ...
- 向上下左右不间断无缝滚动图片的效果(兼容火狐和IE)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- js下载base64格式的图片(兼容火狐)
//下载图片 download() { let imgData = 'data:image/png;base64,iVBORw0KGgoAAAANSUh........'; this.download ...
- 1.2 pip降级selenium3.0
1.2 pip降级selenium3.0 selenium版本安装后启动Firefox出现异常:'geckodriver' executable needs to be in PATHselenium ...
- js兼容火狐显示上传图片预览效果
js兼容火狐显示上传图片预览效果[谷歌也适用] <!doctype html> <html> <head> <meta content="text/ ...
- Selenium2学习(一)-pip降级selenium3.0
selenium版本安装后启动Firefox出现异常:'geckodriver' executable needs to be in PATH selenium默默的升级到了3.0,然而网上的教程都是 ...
随机推荐
- 获取Druid连接池里当前连接数
JdbcTemplate jdbcTemplate=(JdbcTemplate) SpringUtils.getBean("jdbcMysqlTemplate"); DruidDa ...
- Codeforces Round #589 (Div. 2)
目录 Contest Info Solutions A. Distinct Digits B. Filling the Grid C. Primes and Multiplication D. Com ...
- (WAWAWAWAWAWAW) G. Periodic RMQ Problem
没有联通门 : Codeforces G. Periodic RMQ Problem /* Codeforces G. Periodic RMQ Problem MMP 什么动态开点线段树啊 ... ...
- Redis使用总结(二、缓存和数据库双写一致性问题)
首先,缓存由于其高并发和高性能的特性,已经在项目中被广泛使用.在读取缓存方面,大家没啥疑问,都是按照下图的流程来进行业务操作. 但是在更新缓存方面,对于更新完数据库,是更新缓存呢,还是删除缓存.又或者 ...
- 生成一张带有logo的二维码图片
string url = 二维码内容; , , Encoding.UTF8); // 合成活动的LOGO图片 var hasImage = GlobalTools.GetCommonContent(& ...
- ftp连接
package enterprise.celerity.ac.util; import java.io.IOException;import java.io.InputStream;import ja ...
- hive on tez
hive运行模式 hive on mapreduce 离线计算(默认) hive on tez YARN之上支持DAG作业的计算框架 hive on spark 内存计算 hive on tez T ...
- 小程序tab切换代码
<!--index.wxml--> <view class="container"> <view class="navtap" & ...
- 关于bootstrap table 固定列宽
首先为table 设置 style="table-layout: fixed;" <table id="assessStage" data-height= ...
- Facebook开源时间序列内存数据库Beringei,追求极致压缩率——如果是int根据大多数时间序列中的值与相邻数据点相比并没有显著的变化,只要使用XOR将当前值与先前值进行比较,然后存储发生变化的比特。最终,该算法将整个数据集至少压缩了90%
转自:http://www.infoq.com/cn/news/2017/02/Facebook-Beringei 2017年2月3日,Facebook宣布将开源他们的高性能时序数据存储引擎Berin ...