5

I'm trying to run a Python script using Selenium, and while everything runs fine, my personal print() to console lines get hidden between a ton of Selenium/Chromedriver outputs like this:

1128/150256.806:INFO:CONSOLE(0)] "The SSL certificate used to load resources from [some-link.com] will be distrusted in the future. Once distrusted, users will be prevented from loading these resources. See https://g.co/chrome/symantecpkicerts for more information.", source: [current-page.com] (0)

I checked what these links are, and they're just the ads on the pages I'm looking at, so it's completely useless. Also, since the ads are randomly generated every time a page loads/is reloaded, the links are different so the outputs are never-ending. This is incredibly annoying and makes it very hard to see what is actually happening within my program. Is there any way to turn this off with some Selenium options or something?

The strange thing is, running the program in Eclipse Oxygen with PyDev doesn't show any of Selenium's output at all, only if I run it using command line.

EDIT: following the instructions from the possible duplicate mentioned didn't help. I tried setting the logging level to the highest, CRITICAL, and the output mentioned above still went through and flooded the console.

VagrantC
  • 687
  • 2
  • 13
  • 31
  • Possible duplicate of [Turning off logging in Selenium (from Python)](https://stackoverflow.com/questions/9226519/turning-off-logging-in-selenium-from-python) – user1767754 Nov 28 '17 at 23:14
  • Forgot to mention that I saw that, and it didn't help. That doesn't turn off all logging, and even setting the level to CRITICAL didn't remove any of the output I mentioned. – VagrantC Nov 29 '17 at 00:30
  • Maybe the windows CMD outputs stderr and stdout at the same time, according to this (https://sites.google.com/a/chromium.org/chromedriver/logging) _By default ChromeDriver logs only warnings/errors to stderr._ So maybe thats it, try redirecting stderr to null `python yourscript.py 2> nul` – Petar Petrov Dec 01 '17 at 08:53
  • Possible duplicate of [How to suppress console error/warning/info messages when executing selenium python scripts using chrome canary](https://stackoverflow.com/questions/46744968/how-to-suppress-console-error-warning-info-messages-when-executing-selenium-pyth) – JAL Dec 26 '17 at 17:21
  • Hey user3625087, the above duplicate helped me (I set the log level to 3, fatal). If the linked question does not help, I will retract my close vote. – JAL Dec 26 '17 at 17:22

2 Answers2

5

The best Way to solve this problem is to add the --log-level option to your Driver. That would look something like this:

from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument("--log-level=3")
driver = webdriver.Chrome(chrome_options=chrome_options)
Abrogans
  • 179
  • 1
  • 13
  • this doesnt work for me for some reason. still seeing : [WDM] - Current google-chrome version is 85.0.4183 Selenium patched. Safe to import Chrome / ChromeOptions – chadlei Oct 07 '20 at 21:57
1

Whoever uses the ChromeDriverManager via the webdriver_manager package can use the following to disable the [WDM] log messages:

import os
os.environ["WDM_LOG_LEVEL"] = str(logging.WARNING)
martzobg
  • 41
  • 2