3

I'm trying to make selenium take the information that is in the console for my IDE and to save it as a dynamic file instead of it being overwritten.

This is currently what I use to find the console log which works well.

 LogEntries logEntries = driver.manage().logs().get(LogType.BROWSER);
 for (LogEntry entry : logEntries) {
     System.out.println(new Date(entry.getTimestamp()) + " " + entry.getLevel() + " " + entry.getMessage());

My IDE then saves the output to a file. However, I was wondering if there was some way to just take the information from the console into a new file each time? I've done this with screenshots, but not too sure about the console.

3

One thing that could facilitate an answer is to know what is your IDE and if you can configure this behavior of saving in a file.

Considering you can programmatically set configurations of the name of this output file, to make it unique, you could append the time since epoch to its base name.

In Python:

import time
sec_epoch = int(time.time())

In Java:

Date.getTime()

If you can not configure the output file name, you could execute your commands from the terminal and save the content to a file using redirection.

  • Your comment actually worked and made me have another idea where I could just add "-${current_date}.txt" into the output file name which makes it dynamic now. – Christian Nov 28 '16 at 22:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.