Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Selenium 4 - Firefox FirefoxBinary() Deprecated

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.

like image 317
Rhys Avatar asked Apr 22 '26 08:04

Rhys


2 Answers

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)
like image 94
Rhys Avatar answered Apr 24 '26 23:04

Rhys


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)
like image 30
Vitaly Sem Avatar answered Apr 24 '26 22:04

Vitaly Sem



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!