I am wondering how do I disable javascript when using selenium so I can test server side validation.
I found this article but I don\'t know what to really do. Like I
As of 2018 the above solutions didn't work for me for Firefox 61.0.1 and geckodriver 0.20.1.
And here is a solution which works.
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
browser_exe = '/path/to/firefox/exe'
browser_driver_exe = '/path/to/geckodriver/exe'
firefox_binary = FirefoxBinary(browser_exe)
profile = webdriver.FirefoxProfile()
profile.DEFAULT_PREFERENCES['frozen']['javascript.enabled'] = False
profile.set_preference("app.update.auto", False)
profile.set_preference("app.update.enabled", False)
profile.update_preferences()
driver = webdriver.Firefox(
executable_path=browser_driver_exe,
firefox_binary=firefox_binary,
firefox_profile=profile,
)
driver.get("about:config")
Now in the search bar type javascript and you should see the following.