如何在python中的硒中隐藏chromedriver的cmd.exe /控制台日志?

时间:2018-09-07 13:32:00

标签: python selenium selenium-webdriver cmd selenium-chromedriver

如何在python中的硒中隐藏chromedriver的cmd.exe /控制台日志?

我尝试过:

driver.service.stop()

完整代码:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
import time

print("Opening...")
driver = webdriver.Chrome()
driver.get('https://google.com')
driver.service.stop()

但是它没有关闭控制台日志/ cmd.exe

See the console log image

2 个答案:

答案 0 :(得分:0)

您无法将其完全隐藏在Chrome驱动程序中,但是您可以将其隐藏得很少,并按如下所示设置最低日志级别:

from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('log-level=2')

日志级别为

INFO = 0, 
WARNING = 1, 
LOG_ERROR = 2, 
LOG_FATAL = 3.

答案 1 :(得分:-2)

  #Combine this two options: 

  from selenium.webdriver.chrome.options import Options
  from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

  options = Options()
  options.add_argument('--log-level=3')

  dc = DesiredCapabilities.CHROME
  dc['loggingPrefs'] = {'driver': 'OFF', 'server': 'OFF', 'browser': 'OFF'}

  self.driver = webdriver.Chrome(chrome_options=options, desired_capabilities=dc, executable_path="C:\\path\\chromedriver.exe")