You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

将Driver声明为WebDriver后调用ExecuteCdpCommand方法编译报错的解决方案求助

将Driver声明为WebDriver后调用ExecuteCdpCommand方法编译报错的解决方案求助

我们有一套用Visual Studio/C#和Selenium编写的、在Chrome上运行的回归测试套件。

启动代码的一部分如下:

protected static ChromeDriver? Driver { get; set; } = null;
Driver = new ChromeDriver(service, options, TimeSpan.FromSeconds(MaxWait));
Driver.ExecuteCdpCommand(
  "Emulation.setTimezoneOverride",
  new Dictionary<string, object>
  {
     ["timezoneId"] = "Europe/London"
  });

这段ExecuteCdpCommand代码是为了确保在Azure Pipeline执行测试时,某些测试能在英国时区运行,之前一直工作得很好。但现在我们打算隔天轮流在Chrome和Edge上运行夜间回归测试——比如第一天Chrome,第二天Edge,再回到Chrome这样。现在除了ExecuteCdpCommand这部分,其他一切都正常运行。

现在我们把Driver的声明改成了这样:

protected static WebDriver? Driver { get; set; } = null;
Driver = new ChromeDriver(service, options, TimeSpan.FromSeconds(MaxWait));
// 或者根据星期几换成下面的代码
Driver = new EdgeDriver(service, options, TimeSpan.FromSeconds(MaxWait));

结果出现了如下编译错误:

'WebDriver' does not contain a definition for 'ExecuteCdpCommand' and no accessible extension method 'ExecuteCdpCommand' accepting a first argument of type 'WebDriver' could be found (are you missing a using directive or an assembly reference?)

编译报错截图

这实在让人头疼,因为除了这个问题,我们的测试已经准备就绪了。有没有人能帮忙解决这个小问题呢?

备注:内容来源于stack exchange,提问作者Kev

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.14 10:34:31