我正在使用带有Firefox的无头selenium服务器,但是在加载JavaScript时selenium会抛出异常。是否可以在不加考虑地运行selenium时忽略JavaScript。
答案 0 :(得分:0)
如果是PhantomJs Headless Testing,你可以这样做
public static void main(String[] argv) {
// prepare capabilities
Capabilities caps = new DesiredCapabilities();
((DesiredCapabilities) caps).setJavascriptEnabled(false);//by default it was enabled
((DesiredCapabilities) caps).setCapability(
PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
"E:\\browsers\\phantomjs-1.8.2-windows\\phantomjs.exe"
);
WebDriver driver = new PhantomJSDriver(caps);
driver.get("https://www.google.com");
}
如果你想在selenium中以编程方式在firefox中禁用javascript,你可以通过创建来实现 简档
FirefoxProfile profile = new FirefoxProfile();
profile .SetPreference("javascript.enabled", false);
driver = new FirefoxDriver(profile );