ChromeDriver 不记录

ChromeDriver not logging

我开始我的 selenium-driven headless chrome 像这样:

    var options = new ChromeOptions();

    options.AcceptInsecureCertificates = true;

    options.AddArgument("--disable-gpu");
    options.AddArgument("--no-sandbox");
    options.AddArgument("--ignore-certificate-errors");
    options.AddArgument("--disable-web-security");
    options.AddArgument("--allow-insecure-localhost");
    options.AddArgument("--allow-running-insecure-content");
    options.AddArgument("--acceptInsecureCerts=true");
    options.AddArgument("--proxy-server='direct://'");
    options.AddArgument("--proxy-bypass-list=*");
    options.AddArgument("--disable-extensions");
    options.AddArgument("--disable-infobars");
    options.AddArgument("--window-size=1920,1080");
    options.AddArgument("--incognito");
    options.AddArgument("--headless");
    options.AddArgument("--log-level=ALL");
    options.AddArgument("log-path=c:\chromedriver.log");

    options.SetLoggingPreference(OpenQA.Selenium.LogType.Driver, OpenQA.Selenium.LogLevel.All);

    var svc = ChromeDriverService.CreateDefaultService();
    svc.Port = RandomHelper.Randomiser.Next(29700, 29900);

    Context.Driver = new ChromeDriver(svc, options, TimeSpan.FromMinutes(2));

但是,在 运行 之后(并看到成功的测试输出 - 失败和通过测试)我在 c:\chromedriver.log.

看不到任何文件

我做错了什么?

使用 Selenium 进行开发确实令人沮丧,但找到了如何使用 ChromeDriver 进行登录:

var options = new ChromeOptions();
options.AcceptInsecureCertificates = true;

options.AddArgument("--disable-gpu");
options.AddArgument("--no-sandbox");
options.AddArgument("--ignore-certificate-errors");
options.AddArgument("--disable-web-security");
options.AddArgument("--allow-insecure-localhost");
options.AddArgument("--allow-running-insecure-content");
options.AddArgument("--acceptInsecureCerts=true");
options.AddArgument("--proxy-server='direct://'");
options.AddArgument("--proxy-bypass-list=*");
options.AddArgument("--disable-extensions");
options.AddArgument("--disable-infobars");
options.AddArgument("--window-size=1920,1080");
options.AddArgument("--incognito");
options.AddArgument("--headless");
options.AddArgument("--log-level=ALL");
options.AddArgument("log-path=c:\chromedriver.log");

options.SetLoggingPreference(OpenQA.Selenium.LogType.Driver, OpenQA.Selenium.LogLevel.All);

var svc = ChromeDriverService.CreateDefaultService();
svc.Port = RandomHelper.Randomiser.Next(29700, 29900);

svc.LogPath = @"c:\chromedriver.log";
svc.EnableVerboseLogging = true;

options.SetLoggingPreference(LogType.Browser, LogLevel.All);
options.SetLoggingPreference(LogType.Client, LogLevel.All);
options.SetLoggingPreference(LogType.Driver, LogLevel.All);
options.SetLoggingPreference(LogType.Profiler, LogLevel.All);
options.SetLoggingPreference(LogType.Server, LogLevel.All);

Context.Driver = new ChromeDriver(svc, options, TimeSpan.FromMinutes(2));