How to execute Selenium Chrome WebDriver in silent mode?

前端 未结 8 1622
广开言路
广开言路 2020-11-30 06:54

When using Chrome Selenium-WebDriver, it will output diagnostic output when the servers are started:

Started ChromeDriver (v2.0) on port 9515

8条回答
  •  广开言路
    2020-11-30 07:09

    Good question, however, I don't know where you got that .AddArgument("--silent"); thing, as that's Chrome's command line switch, not for ChromeDriver. Also, there isn't a Chrome switch called --silent anyway.

    Under OpenQA.Selenium.Chrome namespace, there is class called ChromeDriverService which has a property SuppressInitialDiagnosticInformation defaults to false. Basically what you might want to do is to create ChromeDriverService and pass it into ChromeDriver's constructor. Please refer to the documentation here.

    Here is the C# code that suppresses ChromeDriver's diagnostics outputs.

    ChromeOptions options = new ChromeOptions();
    
    ChromeDriverService service = ChromeDriverService.CreateDefaultService();
    service.SuppressInitialDiagnosticInformation = true;
    
    IWebDriver driver = new ChromeDriver(service, options);
    

    EDIT: ChromeDriver (not Chrome) has a command line argument --silent, which is supposed to work. SuppressInitialDiagnosticInformation in .NET binding does exactly that. However, it seems only suppress some of the messages.

    Here is a closed chromedriver ticket: Issue 116: How to disable the diagnostic messages and log file from Chrome Driver?

提交回复
热议问题