Unable to hide Chromedriver console with CREATE_NO_WINDOW
Asked Answered
J

3

2
  1. Python 3.11
  2. ChromeDriver 107.0.5304.62
  3. Chrome 107.0.5304.107
  4. Selenium 4.6.0

Chromedriver console always shows when I try to build exe with pyinstaller.

    from selenium import webdriver
    from selenium.webdriver.chrome.service import Service as ChromeService
    from subprocess import CREATE_NO_WINDOW
    
    chrome_options = webdriver.ChromeOptions()
    chrome_options.binary_location = r'D:\Test\bin\chrome.exe'
    
    chrome_service = ChromeService(r'D:\Test\bin\chromedriver.exe')
    chrome_service.creationflags = CREATE_NO_WINDOW
    
    driver = webdriver.Chrome(service=chrome_service, options=chrome_options)
    driver.get('http://google.com')

I have tried to build exe with pyinstaller in different ways:

pyinstaller Test.py
pyinstaller Test.pyw
pyinstaller Test.py  --windowed      or  --noconsole
pyinstaller Test.pyw --windowed      or  --noconsole

I also tried to change in venv\Lib\site-packages\selenium\webdriver\common\service.py at line 67

self.creation_flags = 0

to

self.creation_flags = 1

I also tried different chrome/chromedriver combinations

Jemimah answered 16/11, 2022 at 14:6 Comment(2)
Are there selenium logs appearing on the console window? Please show the text that appears on that console window.Tung
ibb.co/bPbBJ5Q. You can see console log here. It work correctly with 4.5.0. ThanksJemimah
J
1

It doesn't work with selenium 4.6.0 version. It work with selenium 4.5.0

Jemimah answered 17/11, 2022 at 0:31 Comment(0)
D
4

It appears that somewhere along the line (not sure which release), "creationflags" changed to "creation_flags".

Try changing your code from:

chrome_service.creationflags = CREATE_NO_WINDOW

to

chrome_service.creation_flags = CREATE_NO_WINDOW

and see if that works.

Dirty answered 8/12, 2022 at 22:6 Comment(0)
J
2

Try to figure out what happend, I just found this commit change Service varaible from creationflags to creation_flags.

For the people who want to hide the console window for ChromDriver. You have to use selenium with version above 4.0.0.

If before 4.5.0:

chrome_service.creationflags = CREATE_NO_WINDOW

Or after 4.6.0

chrome_service.creation_flags = CREATE_NO_WINDOW
Jota answered 17/3, 2023 at 9:11 Comment(0)
J
1

It doesn't work with selenium 4.6.0 version. It work with selenium 4.5.0

Jemimah answered 17/11, 2022 at 0:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.