How to disable Javascript when using Selenium JAVA?

I use selenium for JAVA web test. I want to stop JavaScript in Firefox browser, Google Chrome browser, IE browser.

I tried this code in Firefox browser.

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("javascript.enabled", false);
WebDriver driver = new FirefoxDriver(profile);

But he returns this error in the second line.

Exception in thread "main" java.lang.IllegalArgumentException: Preference javascript.enabled may not be overridden: frozen value=true, requested value=false

How to disable Javascript when using Selenium for each browser? If you know about this problem, please help me!

+4
source share
1 answer

noscript addon firefox. Firefox , .xpi. Firefox .

FirefoxProfile profile = new FirefoxProfile();
profile.AddExtension(@"PATH\TO\noScript.xpi");
IWebDriver driver = new FirefoxDriver(profile);

driver.Navigate().GoToUrl("http://localhost:8080/");
+3

Source: https://habr.com/ru/post/1608122/


All Articles