1

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?

imrek
  • 2,930
  • 3
  • 20
  • 36

2 Answers2

1

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

mootmoot
  • 12,845
  • 5
  • 47
  • 44
  • OK, thanks for the reference. Actually, what is the preferred way to block 3rd party content (js or other content)? – imrek Apr 18 '16 at 11:17
  • BTW, how do I load driver = ```webdriver.Firefox()``` with an extension enabled? No add-ons are enabled by default. – imrek Apr 18 '16 at 11:31
  • For blocking part. please read the given url. While for second.... will be under another question ;-) Please look for "loading firefox profile in selenium". – mootmoot Apr 18 '16 at 11:59
0

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?

AtachiShadow
  • 381
  • 4
  • 13