【问题标题】:How to turn off the Marionette/gecko driver logs in selenium 3如何在 selenium 3 中关闭 Marionette/gecko 驱动程序日志
【发布时间】:2017-06-01 11:45:52
【问题描述】:

我需要关闭 Marionette/GeckoDriver 日志记录;有什么办法吗?我一直在寻找很多,但我没有得到正确的答案。 INFO 日志是:

 1484653905833  geckodriver INFO    Listening on 127.0.0.1:15106
    Jan 17, 2017 5:21:46 PM org.openqa.selenium.remote.ProtocolHandshake createSession
    INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
    1484653906715   mozprofile::profile INFO    Using profile path C:\Users\vtiger\AppData\Local\Temp\3\rust_mozprofile.7d2LEwDKoE8J
    1484653906720   geckodriver::marionette INFO    Starting browser C:\Program Files\Mozilla Firefox\firefox.exe
    1484653906731   geckodriver::marionette INFO    Connecting to Marionette on localhost:58602
    1484653908388   addons.manager  DEBUG   Application has been upgraded
    1484653908843   addons.manager  DEBUG   Loaded provider scope for resource://gre/modules/addons/XPIProvider.jsm: ["XPIProvider"]
    1484653908846   addons.manager  DEBUG   Loaded provider scope for resource://gre/modules/LightweightThemeManager.jsm: ["LightweightThemeManager"]
    1484653908852   addons.manager  DEBUG   Loaded provider scope for resource://gre/modules/addons/GMPProvider.jsm
    1484653908855   addons.manager  DEBUG   Loaded provider scope for resource://gre/modules/addons/PluginProvider.jsm
    1484653908857   addons.manager  DEBUG   Starting provider: XPIProvider
    1484653908857   addons.xpi  DEBUG   startup
    1484653908858   addons.xpi  INFO    SystemAddonInstallLocation directory

如何关闭此日志记录?

【问题讨论】:

标签: selenium selenium-webdriver gecko geckodriver


【解决方案1】:

您可以通过系统属性将它们发送到 /dev/null 来禁用日志,如下所示:

System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE,"/dev/null");

return new FirefoxDriver();

【讨论】:

  • 这对我有用,即使省略了 DRIVER_USE_MARIONETTE 行 ?
  • 使用 arquillian 我只需要最后一个属性
  • 如何将其设置为日志级别warn
【解决方案2】:

适用于 Windows 和 Linux 的解决方案。

# python 3

# windows
PATH_TO_DEV_NULL = 'nul'
FIREFOX_DRIVER_PATH = 'D:\\path\\to\\geckodriver.exe'

# linux
PATH_TO_DEV_NULL = '/dev/null'
FIREFOX_DRIVER_PATH = '/path/to/geckodriver'

# start browser
driver = webdriver.Firefox(executable_path=FIREFOX_DRIVER_PATH,
                           service_log_path=PATH_TO_DEV_NULL)

【讨论】:

    【解决方案3】:

    尝试了以下代码,但没有成功。看起来像selenium 3.0中的bug

        LoggingPreferences pref = new LoggingPreferences();
        pref.enable(LogType.BROWSER, Level.OFF);
        pref.enable(LogType.CLIENT, Level.OFF);
        pref.enable(LogType.DRIVER, Level.OFF);
        pref.enable(LogType.PERFORMANCE, Level.OFF);
        pref.enable(LogType.PROFILER, Level.OFF);
        pref.enable(LogType.SERVER, Level.OFF);
    
    
        DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();
        desiredCapabilities.setCapability(CapabilityType.LOGGING_PREFS, pref);
    
        WebDriver driver = new FirefoxDriver(desiredCapabilities);
    
        driver.get("https://www.google.com/");
        driver.findElement(By.id("lst-ib")).sendKeys("something");
        Thread.sleep(2000);
        driver.quit();
    

    【讨论】:

    • 即使我也尝试过。我认为这是壁虎驱动程序中的一个错误,将等待下一个版本。
    • 我想是一样的:firefoxOptions.setLogLevel(Level.OFF); capabilities.setCapability("moz:firefoxOptions", firefoxOptions);
    • 有错误报告吗?这个问题解决了吗?
    • 截至 2022 年,仍然无效。
    【解决方案4】:

    一个对某些人有效的选项是here,它使用批处理文件将命令行参数传递给可执行文件。不幸的是,这通常会使额外的进程(geckodriver.exe、cmd.exe)处于打开状态,并且目前还没有针对下一个问题提出解决方案......

    【讨论】:

      【解决方案5】:
        GeckoDriverService gecko = new GeckoDriverService(new File("c:/selenium/geckodriver.exe"), 4444, ImmutableList.of("--log=fatal"), ImmutableMap.of());
        gecko.sendOutputTo(new FileOutputStream("gecko_log.txt"));
        gecko.start();
      
        FirefoxOptions opts = new FirefoxOptions().setLogLevel(Level.OFF);
        DesiredCapabilities capabilities = opts.addTo(DesiredCapabilities.firefox());
        capabilities.setCapability("marionette", true);
        FirefoxDriver driver = new FirefoxDriver(gecko, capabilities);
      

      【讨论】:

        【解决方案6】:

        这可能有点老套,但它可以快速完成工作。鉴于您知道文件的确切位置并在 Linux 上运行代码,您只需 cd 进入该目录并

        rm geckodriver.log
        ln -s /dev/null geckodriver.log
        

        【讨论】:

          【解决方案7】:

          service_log_path 在 python 中似乎是deprecated

          driver.py:77: DeprecationWarning: service_log_path 已被弃用,请传入一个 Service 对象

          现在这对我有用:

          from selenium.webdriver.firefox.service import Service as FirefoxService
          from selenium import webdriver
          
          service = FirefoxService(driver_path, log_path='nul') # Disable logs in windows, for linux probably /dev/null
          
          driver = webdriver.Firefox(
              service=service
          )
          

          【讨论】:

            猜你喜欢
            • 2018-03-17
            • 1970-01-01
            • 1970-01-01
            • 2017-06-03
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2017-04-09
            • 1970-01-01
            相关资源
            最近更新 更多