Ad

Can't Turn Off Javascript Using Selenium

- 1 answer

I'm trying to turn off javascript via the profile when opening using Selenium. This has work previously but now I've updated Selenium/Firfox I can't get it to work.

    profile = webdriver.FirefoxProfile()
    profile.set_preference('javascript.enabled', False)
    driver = webdriver.Firefox(profile)
    driver.implicitly_wait(30)
    driver.get("http://www.enable-javascript.com/")

All other settings seem to change while using profile.set_preference() on other option and javascript.enabled exists and is set to True when I look at the Firefox settings about:config. Is it possible Javascript is being set to True after loading the profile or something?

FF version 43.0.3 Selenium version 2.48.0

Any suggestions on why this could be happening?

UPDATE

Adding profile.add_extension("path/to/noscript_security_suite-2.9.xpi"); to the above code with the downloaded extension as @alecxe suggested fixed the issue.

Ad

Answer

This issue affects selenium starting with 2.46.0, javascript.enabled is being ignored:

As a workaround, load the noscript addon, see:

Ad
source: stackoverflow.com
Ad