You need to enable JavaScript to run this app. C# Selenium测试套件迁移至.NET Core后调用浏览器日志接口报空引用异常
优惠活动
大模型
产品
解决方案
定价
更多

C# Selenium测试套件迁移至.NET Core后调用浏览器日志接口报空引用异常

.NET Core 迁移后Selenium测试方法空引用异常问题

我当前正在将基于C#/Selenium的测试套件从.NET平台迁移至.NET Core。

迁移前,下述代码在对应测试套件中可正常运行:

public void ClearConsoleErrors()
{
    IJavaScriptExecutor js = (IJavaScriptExecutor)Driver;
    String script = "console.clear();";
    js.ExecuteScript(script);
    Driver.Manage().Logs.GetLog(LogType.Browser);
}

迁移后运行上述代码抛出如下错误:

System.NullReferenceException: "Object reference not set to an instance of an object."

错误触发位置为代码行 Driver.Manage().Logs.GetLog(LogType.Browser);,请问各位开发者:

  • 该问题的诱因是什么
  • 应当如何修复

内容的提问来源于stack exchange,提问作者Kev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.17 13:45:02