【问题标题】:C# Automation Edge Browser - using Edge Driver - auto testing program - Failure: No matching capabilities found (SessionNotCreated)C# 自动化边缘浏览器 - 使用边缘驱动程序 - 自动测试程序 - 失败:找不到匹配的功能 (SessionNotCreated)
【发布时间】:2021-12-31 20:39:43
【问题描述】:

问候 stackoverflow 社区,

我正在尝试从这个网站编译和运行程序代码:

https://social.msdn.microsoft.com/Forums/en-US/7bdafd2a-be91-4f4f-a33d-6bea2f889e09/c-sample-for-automating-ms-edge-chromium-browser-using-edge-web-driver

我按照链接中列出的所有说明设置了我想要的路径。

程序和边缘驱动程序开始运行,但随后出现错误。

“WebDriver.dll 中出现错误异常“System.InvalidOperationException”。

更多信息:未创建会话:未找到匹配功能 (SessionNotCreated)"

这是我程序中的代码,或多或少是从上面的链接中复制的:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Edge;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.UI;

namespace ConsoleApplication2
{
class Program
{
    static void Main(string[] args)
    {
        var anaheimService = ChromeDriverService.CreateDefaultService(@"C:\edgedriver_win64", "msedgedriver.exe"); 
           // user need to pass the driver path here....
           var anaheimOptions = new ChromeOptions
           {
               // user need to pass the location of new edge app here....
               BinaryLocation = @"
        C: \Program Files(x86)\Microsoft\Edge\Application\msedge.exe "
           };

        IWebDriver driver = new ChromeDriver(anaheimService, anaheimOptions); -- error appears at this line
        driver.Navigate().GoToUrl("https: //google.com/");
        Console.WriteLine(driver.Title.ToString());
        driver.Close();
     }
   }
}

非常感谢您的帮助!

最好的问候 最大

【问题讨论】:

  • 嗨@blitzmax 这个问题怎么样? my answer below 对处理问题有帮助吗?如果有什么我可以在这里提供帮助的,请告诉我。

标签: c# microsoft-edge browser-automation


【解决方案1】:

您引用的文章有点过时了。现在我们不需要使用ChromeDriver 来自动化 Edge。你可以参考official doc关于如何使用WebDriver自动化Microsoft Edge。

我推荐使用 Selenium 4。这里我安装 Selenium 4.1.0 NuGet 包,示例 C# 代码如下:

using System;
using OpenQA.Selenium.Edge;

namespace WebDriverTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var options = new EdgeOptions();
            options.BinaryLocation = @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe";    
            var driver = new EdgeDriver(@"C:\edgedriver_win64", options);

            driver.Navigate().GoToUrl("https://www.google.com");
            Console.WriteLine(driver.Title.ToString());
            driver.Close();
        }
    }
}

【讨论】:

  • 感谢您的回复!我会试试看。
  • 嗨@blitzmax 测试结果有更新吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-06
  • 1970-01-01
  • 2021-11-25
  • 1970-01-01
相关资源
最近更新 更多