Hide the console in Python Selenium

Last updated:  

python selenium


Running Python Selenium causes the ChromeDriver console window to appear.
In this article, I will note how to hide it.

Environment

  • Windows 10
  • Python 3.9.0
  • selenium 4.0.0b3

Pay attention to the version. In older versions of Selenium, the methods described in this article may not work.
(To install a specific version with pip, use pip install selenium==4.0.0b3, for example)

Source code

The following

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

service = Service('path/to/chromedriver')
service.creationflags = CREATE_NO_WINDOW

driver = webdriver.Chrome(service=service)

You can hide the console window by directly rewriting the creationflags of the Service class.

Reference

Written below.



Related Posts