1

我一直在尝试禁用 DEBUG 消息到控制台,但无论我做什么,它仍然显示在控制台上。我需要找到一种方法来禁用控制台上 HTTP 请求和响应的持续记录。使用的代码:


System.setProperty(ChromeDriverService.CHROME_DRIVER_SILENT_OUTPUT_PROPERTY, "true");
java.util.logging.Logger.getLogger("org.openqa.selenium").setLevel(Level.SEVERE);
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
 

   chromePrefs.put("profile.default_content_settings.popups", 0);
    chromePrefs.put("download.default_directory", downloadPath);
    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("prefs", chromePrefs);

    options.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    options.setCapability(ChromeOptions.CAPABILITY, options);
    // options.setCapability(ChromeOptions.CAPABILITY, options);
    LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
    options.addArguments("--disable-logging");
    options.addArguments("--log-level=3");
    options.addArguments("--silent");
    options.setCapability( "goog:loggingPrefs", logPrefs );
    options.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
    options.setAcceptInsecureCerts(true);
    System.out.println("Launching Google Chrome Browser");
    //ChromeDriverManager.getInstance(CHROME).setup();
    WebDriverManager.chromedriver().setup();
    //   options.merge(cap);



   driver = new ChromeDriver(options);
      
  driver.manage().timeouts().implicitlyWait(TimeOut,TimeUnit.SECONDS);
    driver.manage().window().maximize();

在控制台上

Request DefaultHttpRequest(decodeResult: success, version: HTTP/1.1)
POST /session HTTP/1.1
User-Agent: selenium/4.0.0 (java windows)
Content-Length: 1259
Content-Type: application/json; charset=utf-8
host: localhost:61670
accept: */*

Response DefaultHttpResponse(decodeResult: success, version: HTTP/1.1)
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
cache-control: no-cache
content-length: 788

[AsyncHttpClient-1-2] DEBUG org.asynchttpclient.netty.channel.ChannelManager - Adding key: http://localhost:61670 for channel [id: 0xaa9e94af, L:/127.0.0.1:63133 - R:localhost/127.0.0.1:61670]
[AsyncHttpClient-1-3] DEBUG org.asynchttpclient.netty.channel.NettyConnectListener - Using new Channel '[id: 0x60845110, L:/127.0.0.1:63145 - R:localhost/127.0.0.1:63134]' for 'GET' to '/json/version'
 [AsyncHttpClient-1-3] DEBUG org.asynchttpclient.netty.handler.HttpHandler - 

Request DefaultFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: EmptyByteBufBE)
GET /json/version HTTP/1.1
User-Agent: selenium/4.0.0 (java windows)
host: localhost:63134
accept: */*

Response DefaultHttpResponse(decodeResult: success, version: HTTP/1.1)
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
content-length: 424

我需要找到一种在执行期间删除调试消息的方法,这发生在 selenium 4.0

4

1 回答 1

1

只需更改日志记录级别:

java.util.logging.Logger.getLogger("org.openqa.selenium").setLevel(Level.SEVERE);

至:

java.util.logging.Logger.getLogger("org.openqa.selenium").setLevel(Level.INFO);

或比SEVERE.

请参阅https://docs.oracle.com/javase/7/docs/api/java/util/logging/Level.html

于 2021-11-29T13:08:25.457 回答