Reputation: 13
I've been working on an app to crawl through a list of URLs and pull down the live source code (i.e. generated source instead of raw) - and I've used PhantomJS via Selenium.NET to do this as I wanted to have the operation done in a headless form.
The process itself works fine, but each time one of my threads loads an instance of the PhantomJS driver it runs PhantomJS.exe (as GhostDriver) in a newly opened console. I'd like to avoid this is possible as each time a thread starts the console windows are stealing focus on the machine. Does anyone know whether this is possible? I'm using a really basic snippet to launch the instance:
IWebDriver driver = new PhantomJSDriver();
driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 30));
driver.Navigate().GoToUrl(Entry);
///... Store HTML and do main work here ...
driver.Quit();
driver.Dispose();
Is there a way to hide the exe window via one of the additional capabilities that can be passed into the constructor, or a better way to load the instance via Process.Start etc..?
Any help would be appreciated as I can't seem to find any official documentation dealing with this issue for the .NET platform.
Thanks in advance!
Upvotes: 1
Views: 2307
Reputation: 27486
The appearance of the console window is by design. The developer and maintainer of the .NET bindings believes strongly that launching processes that may output to the console while not displaying the console window is detrimental to debugging efforts. If this is really that huge an issue for you, you can launch PhantomJS.exe using your own System.Diagnostics.Process
object, and use the RemoteWebDriver
class to connect to and control it. Be aware, though, that you are then responsible for the lifetime of the PhantomJS.exe process, and will need to handle closing that process yourself (i.e., you can't rely on driver.Quit()
to exit the process for you, like you can with the browser-specific PhantomJSDriver
class).
Upvotes: 3