1
  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

Ali Sajjad
  • 3,589
  • 1
  • 28
  • 38
Squalo
  • 119
  • 11
  • Are there selenium logs appearing on the console window? Please show the text that appears on that console window. – Ali Sajjad Nov 17 '22 at 06:10
  • http://ibb.co/bPbBJ5Q. You can see console log here. It work correctly with 4.5.0. Thanks – Squalo Nov 17 '22 at 10:49

3 Answers3

3

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.

rkinca
  • 73
  • 7
1

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
Jarvus
  • 11
  • 2
0

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

Squalo
  • 119
  • 11