selenium.common.exceptions.SessionNotCreatedException: Message: Expected browser binary location…

问题描述:

selenium启动firefox浏览器驱动时报错“selenium.common.exceptions.SessionNotCreatedException: Message: Expected browser binary location…”

问题截图:

在这里插入图片描述

问题原因:

可能原因,需逐一排查:
1、系统未安装FireFox浏览器(已安装)
2、驱动和浏览器版本不匹配(驱动和浏览器都是最新的)
3、Firefox没有安装在你系统中的默认位置(装在d盘了)

解决方案:

原因1的解决方案:

安装FireFox浏览器

原因2的解决方案:

安装和浏览器匹配的浏览器驱动

原因3的解决方案一:

在环境变量path中添加firfox.exe的路径

在这里插入图片描述

原因3的解决方案二:

代码中指定firefox文件路径

from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary(r'D:\Program Files\Mozilla Firefox\firefox.exe')
driver = webdriver.Firefox(firefox_binary=binary)

原因3的解决方案三:

①替换firefox路径
②geckodriver未在已配置环境变量的路径(如python的路径下),需设置executable_path字段,路径为geckodriver存放路径
③geckodriver在已配置环境变量的路径(如python的路径下),可不添加executable_path字段

from selenium import webdriver
from selenium.webdriver.firefox.options import Options

options = Options()
options.binary_location = r'D:\Program Files\Mozilla Firefox\firefox.exe'
driver = webdriver.Firefox(options=options, executable_path="C:/location/to/geckodriver.exe")
driver.get("https://www.baidu.com")
  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值