如何在JAVA使用Selenium时禁用Javascript?
我正在使用selenium进行JAVA的web测试。 我想停止Firefox浏览器、Google Chrome浏览器、IE浏览器上的JavaScript 我在Firefox浏览器上尝试了这段代码如何在JAVA使用Selenium时禁用Javascript?,javascript,java,google-chrome,firefox,selenium,Javascript,Java,Google Chrome,Firefox,Selenium,我正在使用selenium进行JAVA的web测试。 我想停止Firefox浏览器、Google Chrome浏览器、IE浏览器上的JavaScript 我在Firefox浏览器上尝试了这段代码 FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("javascript.enabled", false); WebDriver driver = new FirefoxDriver(profile); 但它在第二
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("javascript.enabled", false);
WebDriver driver = new FirefoxDriver(profile);
但它在第二行返回这个错误
Exception in thread "main" java.lang.IllegalArgumentException: Preference javascript.enabled may not be overridden: frozen value=true, requested value=false
如何在使用每个浏览器时禁用Javascript?
如果你知道这个问题,请帮助我 使用。右键单击添加到Firefox按钮并将链接另存为,您可以选择保存.xpi
。然后,按如下方式配置Firefox
探查器
FirefoxProfile profile = new FirefoxProfile();
profile.AddExtension(@"PATH\TO\noScript.xpi");
IWebDriver driver = new FirefoxDriver(profile);
driver.Navigate().GoToUrl("http://localhost:8080/");
谢谢你的回复。我必须在第一次使用该程序的用户的PC上使用。因此我无法生成noScript.xpi。我可以在启动浏览器之前创建配置文件吗?