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.
Just like any other browsers with GUI interface (Firefox, IE, Chrome, etc.), for PhantomJS also, Selenium has a standard API to support the automation. The above code snippet launches Selenium official website on the PhantomJS browser and performs click operation on the download tab.
Being a headless browser, the interactions are much faster than the real browser. So the performance time is smoother in PhantomJS than in Selenium.
PhantomJS is a headless Webkit, which has a number of uses. In this example, we'll be using it, in conjunction with Selenium WebDriver, for conducting basic system tests directly from the command line. Since PhantomJS eliminates the need for a graphical browser, tests run much faster.
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:
var driverService = PhantomJSDriverService.CreateDefaultService();
driverService.HideCommandPromptWindow = true;
var driver = new PhantomJSDriver(driverService);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With