Hide/Silence ChromeDriver window
Asked Answered
L

4

24

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#.

Leisaleiser answered 5/3, 2016 at 18:59 Comment(1)
See answer here sqa.stackexchange.com/questions/7898/…Rufford
S
47

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.

Shrill answered 25/8, 2017 at 16:40 Comment(1)
as of chrome 79, there is no such method as "HideCommandPromptWindow" in ChromeDriverService object.Chaldean
V
26

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");
Virtually answered 5/3, 2016 at 20:50 Comment(2)
That does not work because HideCommandPromptWindow does not existLeisaleiser
The HideCommandPromptWindow property is part of the official Selenium C# client library 2.52.0.0: selenium-release.storage.googleapis.com/2.52/…Virtually
E
0

Hello chrome driver command hide coding

public IWebDriver drv;
public AnaSayfa()
{
    CheckForIllegalCrossThreadCalls = false;
    ChromeDriverService service = ChromeDriverService.CreateDefaultService();
    service.HideCommandPromptWindow = true;
    drv = new ChromeDriver(service);
    InitializeComponent();
}
void BekraHayrNesterGo()
{
    drv.Navigate().GoToUrl("https://www.example.com/");
}

This shape can hide cmd

Eardrum answered 17/1, 2019 at 12:14 Comment(1)
Please do not enter links to your own website, especially without attribution that it is indeed your website. Since it seems irrelevant to the answer, I have changed to the default example.com. Please read How to not be a spammer, and refrain from linking to non-English websites in the future, as Stack Overflow is strictly English-only.Stokehold
P
0

Another hack is to make proxy executable and open hidden process.

rename chromedriver.exe as driver.exe

Build executable as chromedriver.exe from below code. Must use Application Type as Windows Forms Application

'chromedriver.exe
Module Main
    Sub Main(Args As String())
        Dim Info As New ProcessStartInfo("driver.exe", String.Join(" ", Args))
        Info.WindowStyle = ProcessWindowStyle.Hidden
        Process.Start(Info).WaitForExit()
    End Sub
End Module

And use like

Dim Options As New ChromeOptions()
Options.BinaryLocation = "C:\Program Files\Slimjet\slimjet.exe"
Dim Driver = New ChromeDriver(Environment.CurrentDirectory, Options)
Driver.Navigate().GoToUrl("https://www.example.com") '

Note: It assumes both executables are in same directory.

Pun answered 25/2 at 15:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.