我使用的是Chrome驱动程序版本2.33.506120 当我运行测试时,我看到这样的日志:
Starting ChromeDriver 2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f) on port 21961
Only local connections are allowed.
Jan 03, 2018 11:25:37 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
Jan 03, 2018 11:25:37 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
有没有办法禁用这种类型的日志?
注意:我尝试过很多东西,比如Chrome选项," - 禁用日志", " - log-level",功能等在其他地方建议但没有 他们似乎工作。
我的代码如下所示:
System.setProperty("webdriver.chrome.driver", driverLocationClass.getChromeDriverLocation());
/* System.setProperty("webdriver.chrome.logfile", "NUL");
System.setProperty("webdriver.chrome.args", "--disable-logging");
System.setProperty("webdriver.chrome.silentOutput", "true");
*/
DesiredCapabilities cap = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("download.default_directory",
systemProperties.getProperty(AppConstants.SYS_KEY_BROWSER_DOWNLOAD_LOCATION));
options.setExperimentalOption("prefs", chromePrefs);
options.addArguments("--disable-logging");
cap.setCapability(ChromeOptions.CAPABILITY, options);
LoggingPreferences pref = new LoggingPreferences();
pref.enable(LogType.BROWSER, Level.SEVERE);
cap.setCapability(CapabilityType.LOGGING_PREFS, pref);
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
/* LoggingPreferences loggingPreferences = new LoggingPreferences();
loggingPreferences.enable(LogType.BROWSER, Level.SEVERE);
loggingPreferences.enable(LogType.DRIVER, Level.SEVERE);
cap.setCapability(CapabilityType.LOGGING_PREFS, loggingPreferences);*/
d = new ChromeDriver(cap);
d.manage().window().maximize();