在
运行示例源代码http://code.google.com/p/selenium/wiki/GettingStarted
它成功运行,但是Eclipse会抛出大量的WARNING消息。如何禁用此功能?我真正需要的是最后一行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
答案 0 :(得分:7)
zloiadun给出的答案在这里不起作用,而是我必须使用,
Logger logger = Logger.getLogger ("");
logger.setLevel (Level.OFF);
..根据需要更改getLogger(..)和级别。
答案 1 :(得分:7)
虽然这些东西都不适用于我,但我发现我可以通过制作自定义错误处理程序来关闭HTMLUnit ...这有点俗气......但是如果你需要它会给你很好的控制权:
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
}
});
答案 2 :(得分:4)
如此处所述:Can't turn off HtmlUnit logging messages
以下代码最适合我:
static {
java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(java.util.logging.Level.SEVERE);
}
答案 3 :(得分:1)
设置属性有助于:
<强> log4j.logger.com.gargoylesoftware.htmlunit.DefaultCssErrorHandler =错误
我是在 logging.properties 和build.xml的一部分中完成的,例如:
<target name="selenium">
<junit fork="yes" haltonfailure="yes">
<sysproperty key="java.util.logging.config.file" value="WEB-INF/classes/logging.properties" />
...
</junit>
</target>
答案 4 :(得分:0)
HtmlUnit使用Commons Logging。您可以参考here了解更多详情。
作为快速提示,您可以通过设置以下系统属性来禁用警告:
System.getProperties().put("org.apache.commons.logging.simplelog.defaultlog", "fatal");