0

I am trying to hide the CMD window that appears when launching PhantomJS with python:

from selenium import webdriver
browser = webdriver.PhantomJS()

There appears to be a solution when working with C#, however, I was not able to find anything similar for python. Since the feature for C# was added back in 2014, I assume something similar should exist for python too.

I'm using latest PhantomJS and Python 3.6.2.

This is how it looks like:

PhantomJS.exe opens up

  • Maybe this can help you https://stackoverflow.com/questions/25871898/how-to-hide-chromedriver-console-window ? – live2 Jan 02 '18 at 22:20
  • 1
    Perhaps I don't understand how you are launching your code but I have no additional cmd windows open when I use PhantomJS. I do have the original cmd windows of course, the one I used to run the script from. If I launch the script by clicking the python file, it will bring up a cmd window but that's just a regular cmd, not phantomjs related. – Eugene S Jan 03 '18 at 04:11
  • Can you show us a snap of the CMD window? – undetected Selenium Jan 03 '18 at 10:59
  • Added a screenshot for clarity – Mantas Kandratavičius Jan 03 '18 at 15:17

1 Answers1

0

For me, The below code works fine.

driver = webdriver.PhantomJS(
    service_args=service_args,
    desired_capabilities=caps,
    executable_path='phantomjs.exe',
    service_log_path=None
)

Here you have to add service_log_path=None for no log file that's why the console window will get hidden.

Still Not solved then

replace code from

(C:\Users\YOUR_USER_NAME\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\selenium\webdriver\common\service.py) file

self.process = subprocess.Popen(cmd, env=self.env, close_fds=platform.system() != 'Windows', stdout=self.log_file, stderr=self.log_file, stdin=PIPE)

to

self.process = subprocess.Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=False, creationflags=0x08000000)