I tried to use the following code but do not know how to integrated it into existing selenium code:
<Existing code>
IJavaScriptEngine monitor = new JavaScriptEngine(driver);
List<string> consoleMessages = new List<string>();
monitor.JavaScriptConsoleApiCalled += (sender, e) =>
{
consoleMessages.Add(e.MessageContent);
};
await monitor.StartEventMonitoring();
<Existing code>
someButton.Click(); // <== I can never get to this line of code. I'm stuck on the await line.
int messageCount = consoleMessages.Count;
The above code came from the following Selenium Docs link: Selenium Docs BiDi
The problem is that I cannot get past the 'await monitor.StartEventMonitoring()' line of code. I thought I would 'startMonitoring' ... then this monitoring task would run in the background, and the 'someButton.Click()' would then execute. But the code is waiting for 'await monitor.StartEventMonitoring()' line to complete before going onto the next line of code. Guessing this is an issue with my understanding of async/await. I thought the monitor would run in the background and I could then check the consoleMessages List every so often to see if any messages had been added to the list.
I have used the old (old old) method of listening to chrome browser without any issues.
ChromeOptions chromeOptions = new ChromeOptions();
// https://stackoverflow.com/questions/18261338/get-chromes-console-log
var co = new ChromeOptions();
co.SetLoggingPreference(LogType.TestBrowser, LogLevel.All);
<Existing selenium code here>
// Check the log to see if anything had been added
var logList = Driver.Manage().Logs.GetLog(LogType.Browser);
<More existing selenium code here>
But unsure how to use Selenium's BiDi apis