Erling Olsen
Erling Olsen

Reputation: 740

Error update preferences in Firefox profile: 'Options' object has no attribute 'update_preferences'

I can't update my Firefox profile preferences. If I add options.update_preferences () I get an error. I get AttributeError: 'Options' object has no attribute 'update_preferences'

How can I solve?

P.S: I wrote this code, which maybe can be useful to the Stack Overflow community, because the Firefox connection with preferences that has been used for years, has now been deprecated, because firefox_profile has been replaced by the Options object and executable_path by the Service object

from selenium.webdriver import Firefox
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options
   
profile_path = '/home/xxxx/.local/share/torbrowser/tbb/x86_64/tor-browser_en-US/Browser/TorBrowser/Data/Browser/profile.default'

options=Options()
options.set_preference('profile', profile_path)
options.set_preference('network.proxy.type', 1)
options.set_preference('network.proxy.socks', '127.0.0.1')
options.set_preference('network.proxy.socks_port', 9050)
options.set_preference("network.proxy.socks_remote_dns", False)

options.update_preferences() #here

service = Service('/usr/bin/geckodriver')
driver = Firefox(service=service, options=options)
  
driver.get("https://www.google.com")
driver.quit()

Upvotes: 3

Views: 2435

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193128

update_preferences() updates the FirefoxProfile.DEFAULT_PREFERENCES through key, value pairs. It in the FirefoxProfile() class which is now Deprecated.

Instead you have to use Options and your effective working code block will be:

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

profile_path = '/home/xxxx/.local/share/torbrowser/tbb/x86_64/tor-browser_en-US/Browser/TorBrowser/Data/Browser/profile.default'

options=Options()
options.set_preference('profile', profile_path)
options.set_preference('network.proxy.type', 1)
options.set_preference('network.proxy.socks', '127.0.0.1')
options.set_preference('network.proxy.socks_port', 9050)
options.set_preference("network.proxy.socks_remote_dns", False)
service = Service('/usr/bin/geckodriver')
driver = Firefox(service=service, options=options)
driver.get("https://www.google.com")
driver.quit()

PS: Note that when you use options.set_preference() you no more require update_preferences()


References

You can find a couple of relevant detailed discussions in:

Upvotes: 3

Related Questions