imrek
imrek

Reputation: 3040

Selenium Firefox with Python3 FirefoxProfile.set_preference() ignored

I am trying to set different preference values on a selenium 2.53.1 driven Firefox 45.0.1 via Python 3.4. E.g. disabling javascript:

>>> from selenium import webdriver
>>> profile = webdriver.FirefoxProfile()
>>> profile.set_preference('javascript.enabled', False)
>>> driver = webdriver.Firefox(firefox_profile=profile)

However, this is ignored, about:config shows

javascript.enabled  true

and JavaScript code is executed normally. Although about:config does show that it is user set. What is missing?

Upvotes: 1

Views: 1132

Answers (2)

AtachiShadow
AtachiShadow

Reputation: 392

this is a rather old problem, but it is also easily fixed, at least in Selenium 3.14 and Firefox 63:

used Options() for disable JS:

from selenium.webdriver.firefox.options import Options
options = Options()
options.preferences.update({"javascript.enabled": False})
browser = webdriver.Firefox(options=options)
browser.get('about:config')

And this quest was solved here): How to disable Javascript when using Selenium?

Upvotes: 0

mootmoot
mootmoot

Reputation: 13166

You can't

It can no longer be done globally from the User Interface. There are still a few other alternatives. Depending what you need to block it may be worth considering a script blocker something such as

https://support.mozilla.org/en-US/questions/994809

Upvotes: 1

Related Questions