【问题标题】:How to hide cmd.exe/console log of chromedriver in selenium in python?如何在 python 的 selenium 中隐藏 chromedriver 的 cmd.exe/console 日志?
【发布时间】:2018-09-07 13:31:59
【问题描述】:

如何在python中隐藏selenium中chromedriver的cmd.exe/console日志?

我试过了:

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

【问题讨论】:

  • Try driver.quit()
  • @HaR 它关闭 chrome,而不是控制台日志...
  • 欢迎来到 Stack Overflow!请澄清您的具体问题或添加其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。请参阅How to Ask 页面以获得澄清此问题的帮助。
  • @JeffC 我澄清了具体问题,添加了额外的细节,还准确地强调了我需要的东西.....有什么难理解的......?

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


【解决方案1】:

您不能在 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.

【讨论】:

  • 为什么我不能完全隐藏它...?
  • 另外,我尝试了所有四个,options = webdriver.ChromeOptions() options.add_argument('--log-level=0') options.add_argument('--log-level=1') options.add_argument('--log-level=2') options.add_argument('--log-level=3') driver = webdriver.Chrome(chrome_options=options),但没有任何改变......
【解决方案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")

【讨论】:

  • 一些关于如何回答问题的解释会有所帮助。您可以使用答案下方的edit链接补充内容。
猜你喜欢
  • 1970-01-01
  • 2021-12-12
  • 2021-06-04
  • 1970-01-01
  • 1970-01-01
  • 2017-02-24
  • 2016-03-03
相关资源
最近更新 更多