Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to turn off command line logging in Selenium using Chrome in Python

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.

like image 226
user3625087 Avatar asked Nov 28 '17 23:11

user3625087


People also ask

How do I disable Selenium logging?

Set the browserstack. seleniumLogs capability to false to disable Selenium logs. A string. Defaults to true .

How do I disable Chrome drivers command line?

You can kill using below code: Runtime. getRuntime(). exec("taskkill /F /IM ChromeDriver.exe")

How do I close Chrome in Selenium Python?

quit methods which are used to close a browser in Selenium. driver. close() and driver. quit() are two methods for closing a browser session in Selenium WebDriver.


2 Answers

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)
like image 151
Abrogans Avatar answered Oct 21 '22 14:10

Abrogans


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)
like image 1
martzobg Avatar answered Oct 21 '22 14:10

martzobg