3

I'm using Selenium with PowerShell to launch a dashboard display in Internet Explorer on a large monitor in the office. I initiate it like so:

$seleniumOptions = New-Object OpenQA.Selenium.IE.InternetExplorerOptions
$seleniumOptions.BrowserCommandLineArguments = "-k"

$seleniumDriver = New-Object OpenQA.Selenium.IE.InternetExplorerDriver($seleniumOptions)

It all works great. However when it launches an instance of IEDriverServer.exe you see a black console window with debug output. Is there a way to hide this black console window from view?

Thanks.

UPDATE - with a little help from this, mklement0 and JimEvans I've managed to cobble this together and it appears to work - thanks all:

Either (pre-PowerShell 5)

New-Variable -Name IEDS -Value ([OpenQA.Selenium.IE.InternetExplorerDriverService])
$defaultservice = $IEDS::CreateDefaultService()

Or (PowerShell 5)

$defaultservice = [OpenQA.Selenium.IE.InternetExplorerDriverService]::CreateDefaultService()

and then

$defaultservice.HideCommandPromptWindow = $true;

and finally

$seleniumDriver = New-Object OpenQA.Selenium.IE.InternetExplorerDriver -ArgumentList @($defaultservice, $seleniumOptions)
Captain_Planet
  • 1,228
  • 1
  • 12
  • 28
  • 2
    Since you're instantiating a class in-process and want to save the resulting instance in a variable, you get no control over what the class does. So, unless the options you pass to the constructor allow invisible starting of the `*.exe`, the best you can do is to hide the window _after_ it has popped up. As an aside: Please don't use pseudo-method syntax with `New-Object`; the proper form is `New-Object OpenQA.Selenium.IE.InternetExplorerDriver $seleniumOptions`, which is short for `New-Object OpenQA.Selenium.IE.InternetExplorerDriver -ArgumentList $seleniumOptions` – mklement0 Oct 14 '18 at 22:10
  • Possible duplicate of [how-to-run-a-powershell-script-without-displaying-a-window](https://stackoverflow.com/questions/1802127/how-to-run-a-powershell-script-without-displaying-a-window) – lloyd Oct 15 '18 at 03:11

1 Answers1

1

The .NET bindings provide a way to hide the command prompt window spawned by IEDerverServer.exe. Code demonstrating that in C# is listed below. Translating that for use with PowerShell is left as an exercise for the reader.

var service = InternetExplorerDriverService.CreateDefaultService();
service.HideCommandPromptWindow = true;

// Set IE driver options here
var options = new InternetExplorerOptions();

IWebDriver driver = new InternetExplorerDriver(service, options);
JimEvans
  • 27,201
  • 7
  • 83
  • 108