selenium的firefox自动化时使用存在的问题

1.正常调用时存在的问题

import selenium.webdriver
from selenium import webdriver
browser=webdriver.Firefox()

selenium.common.exceptions.SessionNotCreatedException: 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

在通过https://github.com/mozilla/geckodriver/releases/该网址进行下载合适的firefox driver 版本后,将该文件移动到程序所在目录时仍不能解决该问题。

2.通过引入binary来尝试解决问题。

import selenium.webdriver
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

binary = FirefoxBinary(r'E:\firefox\firefox.exe')
browers = webdriver.Firefox(firefox_binary=binary)

在运行后出现以下问题:
DeprecationWarning: firefox_binary has been deprecated, please pass in a Service object
browers = webdriver.Firefox(firefox_binary=binary)
说是firefox已经弃用该服务了,于是通过引入options来解决。(该问题并不影响正常程序运行和服务)

3.使用service和options来尝试解决问题

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


driver_path=(r'E:\firefox\geckodriver.exe')#driver_path就是你的驱动路径
binary_path=(r'E:\firefox\firefox.exe')  #binary_path就是你的游览器路径
ops=Options()
ops.binary_location=binary_path
serve=Service(driver_path)
browers=selenium.webdriver.Firefox(service=serve,options=ops)

可以正常运行该程序,问题解决

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值