How do I suppress console/cmd error messages in python How do I suppress console/cmd error messages in python selenium selenium

How do I suppress console/cmd error messages in python


Those logs are issued by Chrome. You can disable them by launching Chrome with the log level set to Fatal:

options = Options()options.add_argument('--headless')options.add_argument('--hide-scrollbars')options.add_argument('--disable-gpu')options.add_argument("--log-level=3")  # fataldriver = webdriver.Chrome(chrome_options=options)

Though some messages are not filtered by this flag like DevTools listening on ....

To avoid them, you'll have to override the selenium.webdriver.common.service.Service and call subprocess.Popen with close_fds=True to avoid the inheritance of the file descriptor.

self.process = subprocess.Popen(cmd, env=self.env,                                close_fds=True,                                stdout=None,                                stderr=None,                                stdin=None)


I had a similar problem and the following was my sollution.

I was using the selenium module in a python script to open up chromedriver.exe and automate some online downloads.I run the script using a BAT file.

Originally if I ran the BAT file, chrome was opened up and the files where downloaded, but the command line hanged on the log statementDevTools listening on ...

The way I got around this was in the bat file I added the line

taskkill /im chromedriver.exe /f

So my BAT file looked like this

python python_script.pytaskkill /im chromedriver.exe /f

The log statement still appears but killing chromedriver.exe seems to end the run.


Try this:-

options = webdriver.ChromeOptions();options.add_experimental_option('excludeSwitches',['enable-logging']);

Hope it helps.