我正在使用 selenium 通过 JAVA 进行网络测试。 我想在 Firefox 浏览器、Google Chrome 浏览器、IE 浏览器上停止 JavaScript。
我在 Firefox 浏览器上试过这段代码。
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
在每个浏览器中使用 Selenium 时如何禁用 Javascript? 如果你知道这个问题,请帮助我!
最佳答案
使用noscript addon for 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/");
关于javascript - JAVA 使用 Selenium 时如何禁用 Javascript?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32667305/