I'm using Python. I've seen How can I disable javascript in firefox with selenium? which says to create a profile then load the driver with that profile. But I want to disable Javascript after a page has been rendered so this means I can't recreate the driver.
I've tried the following:
browser = selenium.webdriver.Firefox()
browser.get('http://wwwhatever.com')
browser.firefox_profile.set_preference('javascript.enabled', False)
browser.firefox_profile.update_preferences()
But I get this:
print browser.capabilities['javascriptEnabled']
True
Furthermore, the rest of my test still acts like Javascript is enabled.
It is possible with QuickJs extension - https://addons.mozilla.org/en-US/firefox/addon/quickjs/?src=search. This extension add Ctrl+q shortcut to disable javascript. Here is code:
profile = selenium.webdriver.FirefoxProfile()
profile.add_extension("addon-8753-latest.xpi") #QuickJs extension
browser = selenium.webdriver.Firefox(profile)
browser.get('http://wwwhatever.com')
#Turn of javascript, send Ctrl+q
body = browser.find_element_by_tag_name("body")
body.send_keys(selenium.webdriver.common.keys.Keys.CONTROL + 'q')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With