1

I want to capture log for any js event trigger or error Using selenium and java.Any type of help or suggestion will be appreciated? I tried this code but it's not working properly

public void HomePageConsole () throws InterruptedException {
    driver.findElement(By.id("drop-down")).click();
    driver.findElement(By.xpath(".//*[@id='js-top-currency']/li[4]/a")).click();
       LogEntries logEntries = driver.manage().logs().get(LogType.BROWSER);
        for (LogEntry entry : logEntries) {
          // System.out.println(new Date(entry.getTimestamp()) + " " + entry.getLevel() + " " + entry.getMessage());
           //System.out.println("Checking ExitUnit: 5th Line will be true ");
            Thread.sleep(10000);
            System.out.println("Exit Unit Open : "+entry.getMessage().contains("has been triggered!"));

}}
2
  • I already added code, This code word with Mozilla only but sometimes not get appropriate result also result shows by timestamp.I want all log togeather so that I can check Js event Commented May 5, 2017 at 6:50
  • "not working properly" is not a problem description. Commented May 5, 2017 at 13:40

2 Answers 2

4
public void analyzeLog() {

    LogEntries logEntries = driver.manage().logs().get(LogType.BROWSER);
    for (LogEntry entry : logEntries) {
        System.out.println(new Date(entry.getTimestamp()) + " " + entry.getLevel() + " " + entry.getMessage());
        //do something useful with the data
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Does it works in all the browsers? Such as FF, Chrome, IE etc.
0

A bit more efficient way to print the LogEntry by it's own toString override:

LogEntries logEntries = driver.manage().logs().get(LogType.BROWSER);
for (LogEntry entry : logEntries) {
    System.out.println(entry.toString());
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.