Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide/Silence ChromeDriver window

When I launch Selenium's WebDriver (Chromedriver). A console window (chromedriver.exe) runs and it opens Chrome. I need to know how I can hide those like a silent mode because I get messy when there are too many open. I am using C#.

like image 669
user3240928 Avatar asked Mar 05 '16 18:03

user3240928


People also ask

Can Selenium Webdriver open browser windows silently in background?

Selenium Webdriver can run in the background, i.e. without opening a browser window, by running it in Headless mode.

How do I hide Selenium in windows?

We can hide the Firefox window in Selenium webdriver. This can be done by making the browser headless. We shall achieve this with the FirefoxOptions class. We shall then create an object option of that class.

How do I run ChromeDriver in headless mode?

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.


2 Answers

As of Chrome 59, you can now also hide the chrome browser window by using headless mode:

options.AddArgument("headless");

and in combination with:

ChromeDriverService service = ChromeDriverService.CreateDefaultService();
service.HideCommandPromptWindow = true;

it runs in complete silence.

like image 138
mscrivo Avatar answered Oct 10 '22 10:10

mscrivo


To my knowledge it's not possible to hide the browser. However, you can hide the console and set the browser offscreen:

ChromeDriverService service = ChromeDriverService.CreateDefaultService();
service.HideCommandPromptWindow = true;

var options = new ChromeOptions();
options.AddArgument("--window-position=-32000,-32000");

var driver = new ChromeDriver(service, options);
driver.Navigate().GoToUrl("https://www.google.co.uk");
like image 44
Florent B. Avatar answered Oct 10 '22 09:10

Florent B.