Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
414 views
in Technique[技术] by (71.8m points)

java - No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies)

I am trying to run a selenium webdriver code on Firefoxdriver but at the run time i am getting an exception --

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;

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Add dependency (pom.xml)

<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>

As of log4j version 0.8.5, at class initialization time class, the file log4j.properties will be searched from the search path used to load classes

PropertyConfigurator.configure(System.getProperty("user.dir") + "/src/resources/log4j.properties");

Create log4j.properties file

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...