【问题标题】:Python Selenium 4 - Firefox FirefoxBinary() DeprecatedPython Selenium 4 - Firefox FirefoxBinary() 已弃用
【发布时间】:2020-02-06 07:49:04
【问题描述】:

我已升级到 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() 指定参数

有人知道如何实施这些更改吗?我不知道主题标签的含义。我尝试了options.setBinary(),但无法识别setBinary()

【问题讨论】:

  • 您链接到的更改日志不适用于 python 绑定。,

标签: python-3.x selenium geckodriver selenium-firefoxdriver


【解决方案1】:

我已经解决了问题

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)

【讨论】:

    【解决方案2】:

    安装新版本后遇到这个问题,解决方法如下。希望对其他朋友有所帮助。

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.firefox.service import Service
    from selenium.webdriver.firefox.options import Options as options
    from selenium.webdriver.firefox.options import Options as Firefox_Options
    
    firefox_options = Firefox_Options()
    firefox_options.binary = r'C:\Program Files\Mozilla Firefox\firefox.exe';
    
    driver = webdriver.Firefox(executable_path=r'C:\\xampp\\htdocs\\dev\\geckodriver.exe',options=firefox_options)
    
    driver.get('https://google.com')
    

    【讨论】:

      猜你喜欢
      • 2020-03-18
      • 2021-01-10
      • 2021-02-19
      • 2021-12-15
      • 2020-02-09
      • 2019-06-28
      相关资源
      最近更新 更多