How to execute Selenium Chrome WebDriver in silent mode?
Asked Answered
I

9

33

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.

Israelitish answered 9/9, 2013 at 16:13 Comment(2)
I
41

I simply do this

ChromeOptions options = new ChromeOptions();
options.AddArgument("--log-level=3");
IWebDriver driver = new ChromeDriver(options);
Israelitish answered 23/12, 2013 at 17:33 Comment(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]Publish
This solution did not work for me, though Yi Zeng's solution did.Preferment
OMG! This works for me even with Python in Debian 10.Platysma
How do you do that with Python?Glace
@Glace chrome_options = webdriver.ChromeOptions() chrome_options.add_argument('--log-level=3') driver = webdriver.Chrome('C:\webdriver\chromedriver.exe',chrome_options=chrome_options)Christmann
S
16

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?

Suffering answered 10/9, 2013 at 8:21 Comment(6)
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 ?Israelitish
@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.Suffering
is it can be implemented too in Selenium 3 @YiZeng ?Subvention
This works like a charm, however why are you using the options variable? I tried without it and it works fine.Sulfite
@KingMak: Selenium API has long changed since then. I guess ChromeOptions was required when initializing ChromeDriver with service.Suffering
This mostly worked for me, but I also needed to add chrome.AddExcludedArgument("enable-logging"); to suppress the following issueVanthe
G
12

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);
Greasewood answered 14/3, 2018 at 20:40 Comment(1)
This is the correct answer - HideCommandPromptWindow says it allShaving
C
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);
Cytherea answered 29/12, 2015 at 21:22 Comment(0)
B
7

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");
Brachiate answered 13/12, 2017 at 17:27 Comment(0)
B
2

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

Selenium chromedriver disable logging or redirect it java

Blocked answered 30/5, 2020 at 1:6 Comment(0)
S
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

Sevigny answered 28/6, 2022 at 17:12 Comment(0)
R
0

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 { }
}
Resident answered 12/6, 2019 at 10:47 Comment(0)
S
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.

Shotwell answered 6/3, 2020 at 12:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.