I am trying to use PhantomJS with Selenium Webdriver in C#. Following is my code:
IWebDriver driver = new PhantomJSDriver();
driver.Navigate().GoToUrl("http://www.google.com");
Console.WriteLine(driver.Url);
driver.Quit();
The code works fine but whenever it runs, it opens up a cmd window where all the log of the phantomjs is displayed. The cmd is also closed with driver.Quit()
.
The problem is that I do not want the cmd window to be displayed. What should I do to achieve this?
Update: When I do the same code in Python, the cmd window does not show up. But if I convert the python script to exe using py2exe, the cmd windows starts getting displayed again.
No, there is no way to hide the console window of the PhantomJS.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 PhantomJSDriver, since the console window remains open. In the case of some other languages, if your code does not properly clean up the instance of PhantomJSDriver by calling the quit() method on the WebDriver object, you can end up with a zombie PhantomJS.exe process running on your machine.
As JimEvans mentions above, this feature was added in 2.40:
https://code.google.com/p/selenium/source/detail?r=bd0e4ef7504cd6a7f184b19b2aa95b56f8958ab5
I'm not exactly sure how to properly use
PhantomJSDriverService
, but the following works: