Disable javascript in python selenium

Asked 1 years ago, Updated 1 years ago, 81 views

I set the following settings on the webdriver to disable javascript when starting Firefox, but the settings do not take effect.

 from selenium import webdriver
profile=webdriver.FirefoxProfile()
profile.set_preference("javascript.enabled", False)
browser=webdriver.Firefox(firefox_profile=profile)

If you look at the values in Firefox from about:config, the javascript.enabled item is true.
Double-click javascript.enabled on the Firefox about:config screen to false, but you can't manually switch to false every time you take a test

Could you tell me how I can specify the value of javascript.enabled on the python side?

The versions are as follows:
python 3.5.1
selenium 3.3.3
Firefox 51.0.1 (32-bit) Windows 8.1

python firefox selenium

2022-09-30 21:23

2 Answers

 from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options=Options()
options.set_preference('javascript.enabled', False)
browser=webdriver.Firefox(options=options)

Verification OS: Ubuntu 20.04.4 LTS Screenshot


2022-09-30 21:23

browser.get('about:config')
sleep(3)
browser.find_element_by_id('warningButton').click()
browser.find_element_by_id('about-config-search').send_keys('javascript.enabled')
sleep(3)
browser.find_element_by_class_name('button-toggle') .click()


2022-09-30 21:23

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.