C# 在远程会话期间调用driver.Manage().Logs.GetLog()时发生异常
调用C# 在远程会话期间调用driver.Manage().Logs.GetLog()时发生异常,c#,selenium-webdriver,webdriver,remotewebdriver,C#,Selenium Webdriver,Webdriver,Remotewebdriver,调用var entries=driver.Manage()来自我的代码 我正在设置远程驱动程序会话,如下所示: (...) ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.SetLoggingPreference(LogType.Browser, LogLevel.All); webDriver = new RemoteWebDriver(new Uri(remoteServerUrl),chromeOptions
var entries=driver.Manage()代码>来自我的代码
我正在设置远程驱动程序会话,如下所示:
(...)
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.SetLoggingPreference(LogType.Browser, LogLevel.All);
webDriver = new RemoteWebDriver(new Uri(remoteServerUrl),chromeOptions.ToCapabilities());
(...)
通过深入研究这个问题,我发现了一些相互矛盾的报告,其中指出webdriver中GetLogs()方法的C#绑定尚未实现-请参阅。这可以解释我得到的例外
但在这个网站和其他地方也有帖子建议这应该是可行的。比如说
这种情况是否在本地运行但不用于远程webdriver会话时有效
在我拔出头发之前,有人能用C语言一次性确认这个API的当前状态吗?:)
记录在案,我曾尝试使用Webdriver 3.01和2.53。我也遇到了同样的问题,似乎完整的日志集只针对FirefoxDriver
(尽管我不确定这是否仍然适用于Geckodriver版本)
因此,为了有一个可用于所有浏览器的包装器,我创建了以下实用程序方法:
//can also be used in the class constructor
_logs = driver.Manage().Logs;
public void PrintLogs(string logType)
{
try
{
var browserLogs = _logs.GetLog(logType);
if (browserLogs.Count > 0)
{
foreach (var log in browserLogs)
{
//log the message in a file
}
}
}
catch
{
//There are no log types present
}
}
public void PrintAllLogs()
{
PrintLogs(LogType.Server);
PrintLogs(LogType.Browser);
PrintLogs(LogType.Client);
PrintLogs(LogType.Driver);
PrintLogs(LogType.Profiler);
}