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

C#使用Edge Driver自动化Edge浏览器时报No matching capabilities found错误

问题排查与解决方案

错误原因

  • Edge浏览器路径配置错误:你代码中BinaryLocation的属性值包含多余的换行、前后空格,以及盘符后多余的空格,系统无法识别到Edge的可执行文件路径
  • msedgedriver版本和浏览器版本必须严格一致,差一个小版本都可能触发启动失败,如果二者版本不匹配会直接触发能力不匹配报错
  • 如果你使用的是Selenium 4及以上版本,已经不推荐使用ChromeOptions兼容Edge的写法,建议直接使用官方提供的Edge相关类操作
  • 你代码中跳转的URL也包含多余空格,后续执行也会报错

修正后的代码

using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Edge;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            // 配置EdgeDriver服务,路径替换为你本地msedgedriver的存放目录
            var edgeService = EdgeDriverService.CreateDefaultService(@"C:\edgedriver_win64", "msedgedriver.exe");
            var edgeOptions = new EdgeOptions
            {
                // 修正后的Edge浏览器路径,注意不要加多余空格和换行
                BinaryLocation = @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
            };

            // 实例化EdgeDriver,不会再触发之前的报错
            IWebDriver driver = new EdgeDriver(edgeService, edgeOptions);
            // 修正URL中的多余空格
            driver.Navigate().GoToUrl("https://google.com/");
            Console.WriteLine(driver.Title);
            driver.Quit();
        }
    }
}

额外注意事项

如果你坚持要使用旧版Chrome兼容写法,只需要把BinaryLocation的路径修正为无多余空格、无换行的正确路径即可,也能解决当前报错。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.25 00:06:03