无法关闭HTMLUnitDriver警告

时间:2018-01-16 06:27:04

标签: java htmlunit-driver

我无法关闭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]

如何完全关闭这些消息?

0 个答案:

没有答案