Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute Selenium Chrome WebDriver in silent mode?

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.

like image 452
LeMoussel Avatar asked Sep 09 '13 16:09

LeMoussel


People also ask

How do I run ChromeDriver in headless mode?

New Selenium IDE Post version 59, Chrome supports headless execution. ChromeOptions class is utilized to modify the default characteristics of the browser. The addArguments method of the ChromeOptions class is used for headless execution and headless is passed as a parameter to that method.

Can we run Selenium in incognito mode?

New Selenium IDEWe can open a browser window in incognito/private mode with Selenium webdriver in Python using the ChromeOptions class. We have to create an object of the ChromeOptions class. Then apply the method add_argument to that object and pass the parameter -- incognito has a parameter.


2 Answers

I simply do this

ChromeOptions options = new ChromeOptions(); options.AddArgument("--log-level=3"); IWebDriver driver = new ChromeDriver(options); 
like image 87
LeMoussel Avatar answered Sep 28 '22 10:09

LeMoussel


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?

like image 29
Yi Zeng Avatar answered Sep 28 '22 10:09

Yi Zeng