我已经查看了有关此主题的Web搜索结果和有关stackoverflow的答案,但我找不到有相同问题的人。以下是启用我正在使用的性能日志记录的代码:
ChromeOptions options = new ChromeOptions();
// options.addArguments("--headless");
options.addArguments("--remote-debugging-port=9222");
options.addArguments("--no-sandbox");
options.addArguments("--disable-application-cache");
options.addArguments("--disable-notifications");
options.addArguments("--disable-dev-shm-usage");
options.addArguments("--disable-extensions");
options.addArguments("--test-type");
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
//options.addArguments("user-data-dir=C:\apps\selenium\chrome\data");
options.setExperimentalOption("useAutomationExtension", false);
options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
// add Network logging
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
options.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
Map<String, Object> perfLogPrefs = new HashMap<String, Object>();
perfLogPrefs.put("enableNetwork", true);
perfLogPrefs.put("traceCategories", "devtools.network");
options.setExperimentalOption("perfLoggingPrefs", perfLogPrefs);
webDriver = new ChromeDriver(options);
webDriver.manage().deleteAllCookies();
webDriver.manage().window().maximize();
执行时,它会给出以下错误:
Starting ChromeDriver 80.0.3987.16 (320f6526c1632ad4f205ebce69b99a062ed78647-refs/branch-heads/3987@{#185}) on port 27252
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
org.openqa.selenium.InvalidArgumentException: invalid argument: entry 0 of 'firstMatch' is invalid
from invalid argument: perfLoggingPrefs specified, but performance logging was not enabled
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03
我在上面缺少什么?代码示例使用 ChromeDriver(功能(,但已弃用。在添加性能日志记录之前,是否需要启用其他设置?
谢谢
我能够在SeleniumHQ问题上找到答案。从本质上讲,CapabilityType.LOGGING_PREFS在此版本的ChromeDriver中被破坏了。我换了线
options.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
自
options.setCapability("goog:loggingPrefs", logPrefs);
首选项名称已更改为 goog:loggingPrefs 以符合 W3C。在此更改后,我能够收集网络日志。