Java 找不到记录器的附加程序(org.apache.http.client.protocol.RequestAddCookies)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25997556/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies)
提问by Shantanu Nandan
I am trying to run a selenium webdriver code on Firefoxdriver but at the run time i am getting an exception --
我正在尝试在 Firefoxdriver 上运行 selenium webdriver 代码,但在运行时我遇到了异常——
log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
Command duration or timeout: 15 milliseconds
Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:30'
System info: host: 'Admin-PC', ip: '192.168.2.5', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_65'
Session ID: 826ebd51-0bc9-4900-b0ef-d68279bd19fe
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=XP, databaseEnabled=true, cssSelectorsEnabled=true,javascriptEnabled=true, acceptSslCerts=true, handlesAlerts=true, browserName=firefox, webStorageEnabled=true, nativeEvents=false, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=31.0}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:268)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:79)
at ResumeUpdate.Screen_1_Monster.operation(Screen_1_Monster.java:20)
at ResumeUpdate.Screen_1_Monster.main(Screen_1_Monster.java:47)
Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: Element is not currently visible and so may not be interacted with
Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:30'
System info: host: 'Admin-PC', ip: '192.168.2.5', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_65'
Driver info: driver.version: unknown
at <anonymous class>.fxdriver.preconditions.visible(file:///C:/Users/Admin/AppData/Local/Temp/anonymous2662838285289924370webdriver-profile/extensions/[email protected]/components/command_processor.js:8791:5)
at <anonymous class>.DelayedCommand.prototype.checkPreconditions_(file:///C:/Users/Admin/AppData/Local/Temp/anonymous2662838285289924370webdriver-profile/extensions/[email protected]/components/command_processor.js:11438:1)
at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///C:/Users/Admin/AppData/Local/Temp/anonymous2662838285289924370webdriver-profile/extensions/[email protected]/components/command_processor.js:11455:11)
at <anonymous class>.DelayedCommand.prototype.executeInternal_(file:///C:/Users/Admin/AppData/Local/Temp/anonymous2662838285289924370webdriver-profile/extensions/[email protected]/components/command_processor.js:11460:7)
at <anonymous class>.DelayedCommand.prototype.execute/<(file:///C:/Users/Admin/AppData/Local/Temp/anonymous2662838285289924370webdriver-profile/extensions/[email protected]/components/command_processor.js:11402:5)
The code is - import org.openqa.selenium.*; import org.openqa.selenium.firefox.FirefoxDriver;
代码是 - import org.openqa.selenium.*; 导入 org.openqa.selenium.firefox.FirefoxDriver;
public class Screen_1_Monster {
WebDriver driver;
WebElement wb;
public void operation() throws InterruptedException{
driver = new FirefoxDriver();
//going to the desired website
driver.get("https://login.naukri.com/nLogin/Login.php?URL=http%3A%2F%2Fmy.naukri.com%2FMailers%2Fshowdnc%2F%3Furl%3Dhttp%3A%2F%2Fmy.naukri.com%2FHomePage%2Fview%3Fid%3D6e346be1ad03f4d67d75e5911b88ec3df281f50b07bbd08fb4c7f074e87577b79a86cc384cde9c370d99ad6a3af22255");
//User id
wb = driver.findElement(By.id("emailTxt"));
wb.click();
wb.sendKeys("[email protected]");
//Password
wb=driver.findElement(By.id("pwd1"));
wb.click();
wb.sendKeys("2738");
//Login Button
driver.findElement(By.id("sbtLog")).click();
Thread.sleep(20000);
//if Usename/Password is incorrect
wb=driver.findElement(By.id("srvErr"));
String error=wb.getText();
String e=wb.getAttribute("value");
System.out.println(error +" "+ e);
//Get status of Welcome page
String title=driver.getTitle();
System.out.println(title);
}//operation
public static void main(String args[]) throws InterruptedException{
Screen_1_Monster s = new Screen_1_Monster();
s.operation();
}
}//Scrren_1_Monster
采纳答案by Javier92
Infact, the exception you're getting has nothing to do with the warning you mention in your post title.
事实上,您收到的异常与您在帖子标题中提到的警告无关。
The warning: it's only telling you that you did not define any appender (see log4j documentationfor more information) for the selenium driver. So basically, he can't log where you told it to (because you didn't tell him where).
警告:它只是告诉您没有为 selenium 驱动程序定义任何附加程序(有关更多信息,请参阅log4j 文档)。所以基本上,他无法记录你告诉他的地方(因为你没有告诉他在哪里)。
The exception: you told (in your test case) the selenium driver to interact with an element in the web page. The driver didn't find this element, so he can't interact with it.
例外:您告诉(在您的测试用例中)selenium 驱动程序与网页中的元素进行交互。驱动程序没有找到这个元素,所以他不能与之交互。
If you want to google your exception for more infos, look for "Element is not currently visible and so may not be interacted with" instead of the log4j warning :)
如果您想通过谷歌搜索您的异常以获取更多信息,请查找“元素当前不可见,因此可能无法与之交互”而不是 log4j 警告:)
回答by Olegus Testerovichus
Add dependency (pom.xml)
添加依赖(pom.xml)
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
从 log4j version 0.8.5 开始,在 class 初始化 time class 时,将从用于加载类的搜索路径中搜索文件 log4j.properties
PropertyConfigurator.configure(System.getProperty("user.dir") + "/src/resources/log4j.properties");
Create log4j.properties file
创建 log4j.properties 文件
log4j.rootLogger=DEBUG, file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=target/logs/httpClient.log
log4j.appender.file.MaxFileSize=10MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
It's enough.
够了。
回答by avadh goyal
please include this snippet in your code...
请在您的代码中包含此代码段...
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Jdk14Logger");
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Jdk14Logger");
hopre this might help
希望这可能会有所帮助
回答by fty4
For me it was enought to add the following lines at the beginningof the main-class (direct after starting)
对我来说,在主类的开头添加以下几行就足够了(启动后直接添加)
Properties log4jProp = new Properties();
log4jProp.setProperty("log4j.rootLogger", "WARN");
PropertyConfigurator.configure(log4jProp);
回答by Wolfgang Fahl
for me calling the following code helped and shows the general principle:
对我来说,调用以下代码有帮助并显示了一般原则:
/**
* initialize log4J
*/
public static void initLog4J() {
String clazzes[] = { "org.apache.commons.httpclient.HttpClient",
"org.apache.commons.httpclient.params.DefaultHttpParams" };
for (String clazz : clazzes)
org.apache.log4j.Logger.getLogger(clazz)
.setLevel(org.apache.log4j.Level.ERROR);
}
and for Version 2:
对于版本 2:
/**
* initialize log4J
*/
public static void initLog4J() {
// make httpclient shut up see http://stackoverflow.com/a/15798443/1497139
String clazzes[] = { "org.apache.http.wire", "org.apache.http.headers",
"httpclient.wire.content", "httpclient.wire.header",
"org.apache.commons.httpclient",
"org.apache.commons.httpclient.HttpClient",
"org.apache.commons.httpclient.params.DefaultHttpParams" };
for (String clazz : clazzes) {
// https://stackoverflow.com/a/41717213/1497139
Logger logger = org.apache.logging.log4j.LogManager.getLogger(clazz);
Configurator.setLevel(logger.getName(),
org.apache.logging.log4j.Level.ERROR);
}
}