32

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

Started ChromeDriver (v2.0) on port 9515

I do not want to see these messages, how can I suppress them?

I do this

ChromeOptions options = new ChromeOptions();
options.AddArgument("--silent");
IWebDriver Driver = new ChromeDriver(options);

But diagnostic output is not suppress.

John Smith
  • 7,243
  • 6
  • 49
  • 61
LeMoussel
  • 5,290
  • 12
  • 69
  • 122
  • https://stackoverflow.com/a/47496386/551744 – Chaki_Black Oct 22 '19 at 19:54
  • Does this answer your question? [How to disable logging using Selenium with Python binding](https://stackoverflow.com/questions/11613869/how-to-disable-logging-using-selenium-with-python-binding) – architux Mar 06 '20 at 13:54

9 Answers9

40

I simply do this

ChromeOptions options = new ChromeOptions();
options.AddArgument("--log-level=3");
IWebDriver driver = new ChromeDriver(options);
user933
  • 69
  • 1
  • 8
LeMoussel
  • 5,290
  • 12
  • 69
  • 122
  • 5
    holy crap, finally, after two years someone actually posts how to fix this stupid problem that shouldn't be a problem. Thank you very much. For reference, the ruby equivalent of this is `@browser = Watir::Browser.new :chrome , switches: %w[--log-level=3]` – snowe Jan 23 '14 at 23:34
  • This solution did not work for me, though Yi Zeng's solution did. – Frank Schwieterman Dec 06 '14 at 20:27
  • 1
    **OMG!** This works for me even with Python in Debian 10. – Luiz Vaz Jul 24 '20 at 22:16
  • How do you do that with Python? – Menachem Aug 01 '20 at 00:13
  • @Menachem chrome_options = webdriver.ChromeOptions() chrome_options.add_argument('--log-level=3') driver = webdriver.Chrome('C:\webdriver\chromedriver.exe',chrome_options=chrome_options) – Swapnil Aug 13 '21 at 19:47
14

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?

Yi Zeng
  • 32,020
  • 13
  • 97
  • 125
  • Thank's four your help. with your code the Output _Started ChromeDriver (v2.0) on port 9515_ is not display. But output similar to below appears: `[5468:8996:0404/150758:ERROR:textfield.h(156)] NOT IMPLEMENTED` Is it possible to remove this output ? – LeMoussel Sep 10 '13 at 15:47
  • @PapyRef: It depends on how ChromeDriver is designed. If this message is also diagnostics message, then this is a bug, please report it. However, if this is not diagnostics message, then you can only ask for a feature request to suppress this as well. I don't know which does this belong to. – Yi Zeng Sep 11 '13 at 04:48
  • is it can be implemented too in Selenium 3 @YiZeng ? – gumuruh Dec 14 '16 at 01:18
  • This works like a charm, however why are you using the options variable? I tried without it and it works fine. – KingMak Mar 30 '17 at 11:24
  • 1
    @KingMak: Selenium API has long changed since then. I guess `ChromeOptions` was required when initializing `ChromeDriver` with service. – Yi Zeng Mar 31 '17 at 00:49
  • This mostly worked for me, but I also needed to add `chrome.AddExcludedArgument("enable-logging");` to suppress the [following issue](https://stackoverflow.com/questions/47392423/python-selenium-devtools-listening-on-ws-127-0-0-1) – David Rogers Jul 09 '19 at 18:53
11

For me no one of previous answers did not help , my solution was:

ChromeDriverService service = ChromeDriverService.CreateDefaultService(driverLocation);
service.SuppressInitialDiagnosticInformation = true;
service.HideCommandPromptWindow = true;
var driver = new ChromeDriver(service, options);
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Kamornik Cola
  • 644
  • 8
  • 20
8

For me the only thing that worked for

   selenium-chrome-driver-2.48.2.jar
   chromedriver 2.20
   selenium-java-2.48.2.jar

was

   ChromeOptions options = new ChromeOptions();
   System.setProperty("webdriver.chrome.args", "--disable-logging");
   System.setProperty("webdriver.chrome.silentOutput", "true");
   driver = new ChromeDriver(options);
Dan
  • 421
  • 5
  • 12
6

try this code it will hide browser with "headless" Argument but Chrome ver should > 58

( and even you can hide command prompt window )

    IWebDriver driver;
ChromeOptions options = new ChromeOptions();
options.AddArguments("--disable-extensions");
options.AddArgument("test-type");
options.AddArgument("--ignore-certificate-errors");
options.AddArgument("no-sandbox");
options.AddArgument("--headless");//hide browser

ChromeDriverService service = ChromeDriverService.CreateDefaultService(@"chromedriverExepath\");
service.SuppressInitialDiagnosticInformation = true;
//service.HideCommandPromptWindow = true;//even we can hide command prompt window (with un comment this line)  
options.BinaryLocation = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe";
driver = new ChromeDriver(service, options);

driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl("https://www.example.com");
Hassan Saeed
  • 6,326
  • 1
  • 39
  • 37
2

For anyone finding themselves here wanting a Java solution, there is a thread here:

Selenium chromedriver disable logging or redirect it java

MetalRules
  • 189
  • 1
  • 5
1

only add below line System.setProperty("webdriver.chrome.silentOutput", "true");

output:- ChromeDriver was started successfully. Jun 28, 2022 10:38:55 PM org.openqa.selenium.remote.ProtocolHandshake createSession INFO: Detected dialect: W3C

0

To run Chrome browser with Selenium in console in completely silent mode, you should use this snippet:

options = Options()
options.headless = True
options.add_experimental_option("excludeSwitches", ["enable-logging"])

That trick will suppress any console message from either the Selenium driver or the browser itself, including the first message DevTools listening on ws://127.0.0.1 at the very start.

architux
  • 607
  • 7
  • 13
-1

This code works fine for me:

public static IWebDriver Driver { set; get; }
-----
Driver = CreateBrowserDriver();

////////////// Create Driver
private static IWebDriver CreateBrowserDriver()
{
    try
    {
        var options = new OpenQA.Selenium.Chrome.ChromeOptions();
        options.AddArguments("--disable-extensions");
        options.AddArgument("--headless"); // HIDE Chrome Browser
        var service = OpenQA.Selenium.Chrome.ChromeDriverService.CreateDefaultService();
        service.HideCommandPromptWindow = true; // HIDE Chrome Driver
        service.SuppressInitialDiagnosticInformation = true;

        return new OpenQA.Selenium.Chrome.ChromeDriver(service, options);
    }
    catch
    {
        throw new Exception("Please install Google Chrome.");
    }
}
////////////// Exit Driver
public static void ExitDriver()
{
    if (Driver != null)
    {
        Driver.Quit();
    }

    Driver = null;

    try
    {
        // Chrome
        System.Diagnostics.Process.GetProcessesByName("chromedriver").ToList().ForEach(px => px.Kill());
    }
    catch { }
}
Haddad
  • 301
  • 3
  • 5