Enabling "Preserve Log" in Chrome Developer Tools Console via Selenium

55 views
Skip to first unread message

CCT TestPSQA

unread,
Dec 1, 2023, 5:28:27 AM12/1/23
to Selenium Users

Hello Selenium Community,

I hope you're doing well. I'm currently facing a challenge in my Selenium automation project where I need to enable the "Preserve Log" option in the Chrome Developer Tools Console programmatically.

I'm using ChromeDriver to interact with the Chrome browser, and I've attempted different approaches, such as utilizing the AddUserProfilePreference method in ChromeOptions and executing JavaScript through IJavaScriptExecutor. Despite my efforts, the "Preserve Log" option in the Console tab remains unchecked.

Here's a snippet of the code I'm currently using:

 var options = new ChromeOptions();
 //options.AddArgument("incognito");
 options.AddArguments("disable-infobars");
 // options.AddArguments("--headless");

 //Session 0 limit - 1024 x 768
 options.AddArguments("--window-size=1024,768");
 options.AddArguments("--window-position=0,0");
 options.AddArgument($"--user-agent= {userAgent}");
 options.SetLoggingPreference(LogType.Browser, LogLevel.All);

options.AddUserProfilePreference("console.log.preserveLog", true);

// Or

IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
js.ExecuteScript("console.preserveLog = true;");

Unfortunately, these methods have not produced the desired result. I'm reaching out to the Selenium community to seek guidance, insights, or alternative approaches that might help me achieve this goal.

If there's a specific preference, command-line argument, or technique that I might be missing, please share your expertise. Your assistance is highly appreciated.

Environment Details:

  • Chrome Version: 119
  • Selenium Version: 4.0
Reply all
Reply to author
Forward
0 new messages