0

I am attempting to automate a website process with Selenium in Python. I am using ChromeDriverManager to install the correct version of Chrome driver upon the execution of my program. I have a GUI program that calls my Selenium program via command-line arguments. My goal is to execute this program without any extra pop-ups from chromedriver.exe. I have the following code:

op = webdriver.ChromeOptions()
op.ignore_zoom_level = True
op.add_argument('headless')
op.add_argument('disable-gpu')
op.add_argument('disable-infobars')
op.add_experimental_option('excludeSwitches', ['enable-logging'])
driver = webdriver.Chrome(ChromeDriverManager().install(), options=op, service_args=['CREATE_NO_WINDOW'])

When I run this code via script I see no windows from chromedriver.exe, however, when I export to EXE package via pyinstaller a chromedriver.exe window pops up: Terminal IMG

How do I disable this terminal window from chromedriver.exe from popping up?

To clarify this is not an issue with the main program appearing in the terminal. It is an issue when the main program executes chromedriver.exe.

  • do you add the arg ``--windowed`` when you compile? – Obaskly Feb 27 '22 at 02:50
  • Use bonigracia's Webdrivermanager jar.it will intsall the correct version of chrome driver based on the Chrome browser version. – Sonali Das Feb 27 '22 at 02:54
  • @Obaskly Can you please clarify where exactly I would run "--windowed"? I do not believe Selenium allows for command-line arguments to be passed to the driver when you initialize it. – DracoGlacies Feb 27 '22 at 16:24
  • @Sonali Is there a benefit to using bonigracia's Webdrivermanager compared to my current setup? Is there an option to fix my issue via bonigracia? – DracoGlacies Feb 27 '22 at 16:28
  • @DracoGlacies When compiling with pyinstaller, you use the command: ``pyinstaller --onfile script.py``, you should add the argument ``--windowed`` as well if you are using a gui, the arg ``--noconsole`` works fine too. – Obaskly Feb 28 '22 at 13:27
  • @Obaskly Thank you for the suggestion. Unfortunately, this is not a solution. The problem stems from the chromedriver.exe execution not the execution of the main program itself. I have tried --windowed, --noconsole, and also a .pyw script when using pyinstaller. Where these keep the main program from appearing, they do not keep the chromedriver.exe terminal from appearing. – DracoGlacies Mar 01 '22 at 00:20

5 Answers5

2

You are passing arguments to ChromeOptions wrongly. You are missing -- in all the arguments.
Please try this:

op = webdriver.ChromeOptions()
op.ignore_zoom_level = True
op.add_argument('--headless')
op.add_argument('--disable-gpu')
op.add_argument('--disable-infobars')
op.add_experimental_option('excludeSwitches', ['enable-logging'])
driver = webdriver.Chrome(ChromeDriverManager().install(), options=op, service_args=['CREATE_NO_WINDOW'])
Prophet
  • 32,350
  • 22
  • 54
  • 79
2

Upon additional research, I found a solution to the issue. I added a service creation flag CREATE_NO_WINDOW and this solved the issue. Code change reference below:

from selenium.webdriver.chrome.service import Service as ChromeService
from subprocess import CREATE_NO_WINDOW

op = webdriver.ChromeOptions()
op.ignore_zoom_level = True
op.add_argument('--headless')
op.add_argument('--disable-gpu')
op.add_argument('--disable-infobars')
op.add_experimental_option('excludeSwitches', ['enable-logging'])

serv = ChromeService(ChromeDriverManager().install())
serv.creationflags = CREATE_NO_WINDOW

driver = webdriver.Chrome(service=serv, options=op)
0

Unable to hide Chromedriver console with CREATE_NO_WINDOW

chrome_service.creationflags = CREATE_NO_WINDOW

CREATE_NO_WINDOW only works with selenium 4.5.0 and doesn't work with higher version

yen612
  • 1
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 09 '23 at 03:51
-1

For me CREATE_NO_WINDOW gave nothing so I made a taskkill with filters to stop only the chromedriver.exe window

# /fi "memusage lt 12000" allows to filter processes under 12 Mb
subprocess.call('taskkill /f /IM chromedriver.exe /fi "memusage lt 12000"')
MARI Mathieu
  • 39
  • 1
  • 8
-1
import os,logging
os.environ["WDM_LOG_LEVEL"] = str(logging.WARNING)
Kepa
  • 9
  • 2
  • 1
    Please see [How to answer](https://stackoverflow.com/help/how-to-answer) for details on how to provide quality answers. It's useful to provide context and details on why this might be an ideal solution. – arkon Mar 19 '22 at 15:18