What I want to do:
I want to open Chrome browser using Selenium ChromeDriver without the Chrome messages getting output to the console.
What I did:
from selenium import webdriver
driver = webdriver.Chrome(r'C:\Users\u1\Documents\scripts\chromedriver.exe')
Output:
C:\Users\u1\Documents\scripts>python test.py
DevTools listening on ws://127.0.0.1:50605/devtools/browser/11c9063a-44ce-4b39-9566-9e6c6270025c
I want to hide the output message "DevTools listening on..."
What I tried to solve this:
Using contextlib
from selenium import webdriver
import contextlib
with contextlib.redirect_stdout(None):
driver = webdriver.Chrome(r'C:\Users\u1\Documents\scripts\chromedriver.exe')
Using devnull
from selenium import webdriver
import subprocess
devnull = subprocess.DEVNULL
subprocess.Popen(open_browser(), stdout=devnull, stderr=devnull)
def open_browser():
driver = webdriver.Chrome(r'C:\Users\u1\Documents\scripts\chromedriver.exe')
Using log-level=3
chrome_options = Options()
chrome_options.add_argument("--log-level=3")
driver = webdriver.Chrome(r'C:\Users\u1\Documents\scripts\chromedriver.exe', chrome_options=chrome_options)
But still the message is getting displayed. How do I hide the output message "DevTools listening on..." in Python?