无法关闭 HTMLUnitDriver 警告



>我无法关闭 HTML 单元驱动程序警告。下面的代码减少了原始警告的数量。无法关闭最后一位。

我无法关闭 HTML 单元驱动程序警告。下面的代码减少了原始警告的数量。无法关闭最后一位。

我的代码:

  LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");
  java.util.logging.Logger.getLogger("org.apache.commons.httpclient").setLevel(Level.OFF);
  java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(java.util.logging.Level.OFF);
  java.util.logging.Logger.getLogger("org.apache.http").setLevel(java.util.logging.Level.OFF);
  java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF); 
  htmlDriver = new HtmlUnitDriver(browserVersion, isJavaScriptEnabled) {
    @Override
    protected WebClient modifyWebClient(WebClient client) {
      WebClient modifiedClient = super.modifyWebClient(client);
      modifiedClient.getOptions().setThrowExceptionOnScriptError(false); // see here
      modifiedClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
      modifiedClient.getOptions().setJavaScriptEnabled(isJavaScriptEnabled);
      modifiedClient.setCssErrorHandler(new SilentCssErrorHandler());
      modifiedClient.getOptions().setCssEnabled(false);
      modifiedClient.getOptions().setPrintContentOnFailingStatusCode(false);
      modifiedClient.getOptions().setTimeout(10000);
      modifiedClient.setIncorrectnessListener(new IncorrectnessListener() {
        @Override
        public void notify(String arg0, Object arg1) {
          // TODO Auto-generated method stub
        }
      });
      modifiedClient.setJavaScriptErrorListener(new JavaScriptErrorListener() {
        @Override
        public void timeoutError(HtmlPage arg0, long arg1, long arg2) {
          // TODO Auto-generated method stub
        }
        @Override
        public void scriptException(HtmlPage arg0, ScriptException arg1) {
          // TODO Auto-generated method stub
        }
        @Override
        public void malformedScriptURL(HtmlPage arg0, String arg1, MalformedURLException arg2) {
          // TODO Auto-generated method stub
        }
        @Override
        public void loadScriptError(HtmlPage page, java.net.URL scriptUrl,
                                    Exception exception) {
          // TODO Auto-generated method stub
        }
      });
      modifiedClient.setHTMLParserListener(new HTMLParserListener() {
        @Override
        public void error(String message, java.net.URL url, String html, int line, int column,
                          String key) {
          // TODO Auto-generated method stub
        }
        @Override
        public void warning(String message, java.net.URL url, String html, int line, int column,
                            String key) {
          // TODO Auto-generated method stub
        }
      });
      modifiedClient.setHTMLParserListener(new HTMLParserListener() {
        @Override
        public void error(String message, URL url, String html, int line, int column,
                          String key) {
          // TODO Auto-generated method stub
        }
        @Override
        public void warning(String message, URL url, String html, int line, int column,
                            String key) {
          // TODO Auto-generated method stub
        }
      });
      modifiedClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
      modifiedClient.getOptions().setThrowExceptionOnScriptError(false);

      return modifiedClient;
    }
  };

但我仍然得到:

01:12:36.667 [Thread-10] ERROR c.g.h.javascript.StrictErrorReporter - runtimeError: message=[An invalid or illegal selector was specified (selector: 
01:12:37.264 [Thread-10] ERROR c.g.h.javascript.StrictErrorReporter - runtimeError: message=[An invalid or illegal selector was specified (selector: '*,:x' error: Invalid selector: :x).] sourceName=[http://code.jquery.com/jquery-1.9.1.js] line=[4224] lineSource=[null] lineOffset=[0]
01:12:38.393 [JS executor for com.gargoylesoftware.htmlunit.WebClient@4c085759] ERROR c.g.h.javascript.StrictErrorReporter - runtimeError: message=[An invalid or illegal selector was specified (selector: '*,:x' error: Invalid selector: :x).] sourceName=[http://code.jquery.com/jquery-1.9.1.js] line=[4224] lineSource=[null] lineOffset=[0]
01:12:41.251 [JS executor for com.gargoylesoftware.htmlunit.WebClient@4c085759] ERROR c.g.h.javascript.StrictErrorReporter - runtimeError: message=[An invalid or illegal selector was specified (selector: ':text' error: Invalid selector: :text).] sourceName=[http://code.jquery.com/jquery-1.9.1.js] line=[3983] lineSource=[null] lineOffset=[0]
01:12:41.256 [JS executor for com.gargoylesoftware.htmlunit.WebClient@4c085759] ERROR c.g.h.javascript.StrictErrorReporter - runtimeError: message=[An invalid or illegal selector was specified (selector: ':text' error: Invalid selector: :text).] sourceName=[http://code.jquery.com/jquery-1.9.1.js] line=[3983] lineSource=[null] lineOffset=[0]

如何完全关闭这些消息?

您需要禁用从登录 XML 进行日志记录这种停用

java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF);

不起作用,我认为他们使用 locgback,也不能从 log4j 配置中禁用它

com.gargoylesoftware.htmlunit.level = WARNING
com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter.level = OFF 

您的登录中需要类似的东西.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
            </pattern>
        </encoder>
    </appender>
    <root level="INFO">
        <appender-ref ref="STDOUT" />
    </root>
    <logger name="com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter" level="OFF" />
</configuration> 

相关内容

  • 没有找到相关文章

最新更新