10

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)

or

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

Return this error message

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

Documentation

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

Says

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()

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.

Rhys
  • 4,926
  • 14
  • 41
  • 64

4 Answers4

14

I have solved the issue

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)
Jonny Henly
  • 4,023
  • 4
  • 26
  • 43
Rhys
  • 4,926
  • 14
  • 41
  • 64
1

Actually you need to import a Service class from selenium.webdriver.firefox.service and put executable_path into Service.

from selenium.webdriver.firefox.service import Service

service = Service(executable_path="path_to_your_webdriver")
driver = webdriver.Firefox(service=service)
Vitaly Sem
  • 11
  • 2
0

After installing the new version I encountered this problem and solved it as follows. I hope it helps to other friends.

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')
Fazıl Akbulut
  • 198
  • 2
  • 14
  • This still throws the warning, and does not address the "Service object" warning. ```C:\Users\PowerUser\AppData\Local\Temp\ipykernel_29492\1343136057.py:10: DeprecationWarning: executable_path has been deprecated, please pass in a Service object driver = webdriver.Firefox(executable_path=r'C:\\webdrivers\\geckodriver.exe',options=firefox_options)``` – Rich Lysakowski PhD Oct 21 '22 at 22:33
0

This error message...

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

...implies that the argument executable_path is deprecated now and you need to pass a Service object instead.


Details

This error is inline with the current implementation of webdriver and as per webdriver.py

if executable_path != DEFAULT_EXECUTABLE_PATH:
    warnings.warn('executable_path has been deprecated, please pass in a Service object',
                  DeprecationWarning, stacklevel=2)

additionally:

if firefox_binary:
    warnings.warn('firefox_binary has been deprecated, please pass in a Service object',
                  DeprecationWarning, stacklevel=2)

Solution

As per Selenium v4.0 Beta 1:

  • Deprecate all but Options and Service arguments in driver instantiation. (#9125,#9128)

So:

  • Instead of executable_path you have to use an instance of Service().

  • Instead of firefox_binary you have to use the binary_location property and pass it through an instance of FirefoxOptions().

  • You can use the following code block:

    from selenium import webdriver
    from selenium.webdriver.firefox.service import Service
    
    option = webdriver.FirefoxOptions()
    option.binary_location = '/path/to/firefox'
    driverService = Service('/path/to/geckodriver')
    driver = webdriver.Chrome(service=driverService, options=option)
    driver.get("https://www.google.com")
    

References

You can find a couple of relevant detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352