可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
Running the example source at
http://code.google.com/p/selenium/wiki/GettingStarted
It runs successfully, however Eclipse throws bunch of WARNING messages. How Can I disable this from displaying ? All I really need is the last line Page title is: Cheese! - Google Search
17-Aug-2010 12:07:00 AM com.gargoylesoftware.htmlunit.util.StringUtils parseHttpDate WARNING: Unable to parse date: -1 17-Aug-2010 12:07:00 AM com.gargoylesoftware.htmlunit.util.StringUtils parseHttpDate WARNING: Unable to parse date: -1 17-Aug-2010 12:07:01 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error WARNING: CSS error: null [1:4686] Error in style rule. Invalid token "*". Was expecting one of: <S>, "}", ";", <IDENT>. 17-Aug-2010 12:07:01 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler warning WARNING: CSS warning: null [1:4686] Ignoring the following declarations in this rule. 17-Aug-2010 12:07:01 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error WARNING: CSS error: null [1:6505] Error in expression. Invalid token ";". Was expecting one of: <S>, <PLUS>, "-", <HASH>, <STRING>, <URI>, "inherit", <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <DIMENSION>, <PERCENTAGE>, <NUMBER>, <FUNCTION>, <IDENT>. Page title is: Cheese! - Google Search
回答1:
The answer given by zloiadun didn't work here, instead I had to use,
Logger logger = Logger.getLogger (""); logger.setLevel (Level.OFF);
.. changing the getLogger( .. ) and level as needed.
回答2:
Though none of these things worked for me, I found that I could shut HTMLUnit up by making a custom errorhandler... this is kinda cheesy... but it gives you excellent control should you need it:
webClient.setCssErrorHandler(new ErrorHandler() { //Saint @Override public void warning(CSSParseException arg0) throws CSSException { // stare blankly } @Override public void fatalError(CSSParseException arg0) throws CSSException { // twiddle thumbs } @Override public void error(CSSParseException arg0) throws CSSException { // drool on shirt } });
回答3:
As discussed here: Can't turn off HtmlUnit logging messages
The following code worked best for me:
static { java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(java.util.logging.Level.SEVERE); }
回答4:
Setting the property helps:
log4j.logger.com.gargoylesoftware.htmlunit.DefaultCssErrorHandler=ERROR
I did it in logging.properties and piece of my build.xml, for instance:
<target name="selenium"> <junit fork="yes" haltonfailure="yes"> <sysproperty key="java.util.logging.config.file" value="WEB-INF/classes/logging.properties" /> ... </junit> </target>
回答5:
HtmlUnit uses the Commons Logging. You can refer here for more details.
As quick hint, you can disable warnings by setting the following system property:
System.getProperties().put("org.apache.commons.logging.simplelog.defaultlog", "fatal");