ChromeDriver console application hide

前端 未结 5 623
借酒劲吻你
借酒劲吻你 2020-12-01 18:04

I have created a player which will automate chrome using selenium and ChromeDriver in C#. It\'s working fine.

Issue what I am facing is, when it creates an object fo

相关标签:
5条回答
  • 2020-12-01 18:43

    As an update to this question. Yes, you can hide command prompt window in Selenium 2.40.0 and up. Please note that hiding command prompt window is not recommended but you can do it. As the question refers to C# you do it with the next code:

    ChromeDriver

    var driverService = ChromeDriverService.CreateDefaultService();
    driverService.HideCommandPromptWindow = true;
    
    var driver = new ChromeDriver(driverService, new ChromeOptions());
    

    InternetExplorerDriver

    var driverService = InternetExplorerDriverService.CreateDefaultService();
    driverService.HideCommandPromptWindow = true;
    
    var driver = new InternetExplorerDriver(driverService, new InternetExplorerOptions());
    

    PhantomJSDriver

    var driverService = PhantomJSDriverService.CreateDefaultService();
    driverService.HideCommandPromptWindow = true;
    
    var driver = new PhantomJSDriver(driverService);
    
    0 讨论(0)
  • 2020-12-01 18:55

    Yes, you need modify source code in WebDriver\DriverService.cs in Start(); add:

    this.driverServiceProcess.StartInfo.CreateNoWindow = true;
    
    0 讨论(0)
  • 2020-12-01 18:57

    Modifying source code in WebDriver\DriverService.cs is not necessary for this in latest WebDriver. You just need to instantiate ChromeDriverService and set HideCommandPromptWindow to true and then instantiate ChromeDriver by that service and ChromeOptions. I am giving C# code example below

    var chromeDriverService = ChromeDriverService.CreateDefaultService();
    chromeDriverService.HideCommandPromptWindow = true;
    return new ChromeDriver(chromeDriverService,  new ChromeOptions());
    
    0 讨论(0)
  • 2020-12-01 19:00

    No, there is no way to hide the console window of the chromedriver.exe in the .NET bindings without modifying the bindings source code. This is seen as a feature of the bindings, as it makes it very easy to see when your code hasn't correctly cleaned up the resources of the ChromeDriver, since the console window remains open. In the case of some other languages, if your code does not properly clean up the instance of ChromeDriver by calling the quit() method on the WebDriver object, you can end up with a zombie chromedriver.exe process running on your machine.

    0 讨论(0)
  • 2020-12-01 19:03

    This is possible now, using the headless option. Might not have been available then. Running Chrome Headless

    Translated into C#, you can do this:

    ChromeOptions options = new ChromeOptions();
    options.AddArgument("headless");
    ChromeDriver driver = new ChromeDriver(options);
    

    Now the browser window is invisible, while the rest of the program stays the same.

    0 讨论(0)
提交回复
热议问题