Python Selenium 4-不推荐使用Firefox FirefoxBinary() [英] Python Selenium 4 - Firefox FirefoxBinary() Deprecated

查看:372
本文介绍了Python Selenium 4-不推荐使用Firefox FirefoxBinary()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经升级到Selenium 4

I have upgraded to Selenium 4

new_binary_path = FirefoxBinary('path_to_binary')
selenium.webdriver.Firefox(executable_path=path, options=ops, firefox_binary=new_binary_path)

options.add_argument("--setBinary(path_to_binary)")
selenium.webdriver.Firefox(executable_path=path, options=ops)

返回此错误消息

DeprecationWarning: executable_path has been deprecated, please pass in a Service object

文档

https://github.com/SeleniumHQ/selenium/blob/master/javascript/node/selenium-webdriver/CHANGES.md

删除了firefox.Binary类.自定义二进制文件仍然可以使用firefox.Options#setBinary()选择.同样,自定义二进制参数可以使用firefox.Options#addArguments()

Removed the firefox.Binary class. Custom binaries can still be selected using firefox.Options#setBinary(). Likewise, custom binary arguments can be specified with firefox.Options#addArguments()

有人知道如何实施这些更改吗?我不知道井号是什么意思.我尝试了 options.setBinary(),但未识别出 setBinary().

Does anyone know how to implement these changes? I don't know what the hashtag means. I tried options.setBinary() but setBinary() is not recognised.

推荐答案

我已经解决了问题

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

    #///////////////// Init binary & driver
    new_driver_path = 'path to driver'
    new_binary_path = 'path to binary'

    ops = options()
    ops.binary_location = new_binary_path
    serv = Service(new_driver_path)
    browser1 = selenium.webdriver.Firefox(service=serv, options=ops)

这篇关于Python Selenium 4-不推荐使用Firefox FirefoxBinary()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆