selenium chromedriver 不会连接到给定的调试端口 c#

selenium chromedriver won't connect to the given debug port c#

我正在使用 selenium 连接到基于 cefsharp 的浏览器的外部应用程序(浏览器应用程序工作正常)问题是无论我设置什么端口我都无法设置调试端口。 chromedriver.exe 打开了它自己选择的端口,它甚至没有打开我的 cefbased.exe 浏览器。 这是我的代码

        ChromeDriverService service = ChromeDriverService.CreateDefaultService();
        service.HideCommandPromptWindow = true;
        ChromeOptions options = new ChromeOptions();
        string hostname = "localhost";
        int portno = 12345;//just an example
        IPAddress ipa = (IPAddress)Dns.GetHostAddresses(hostname)[0];

        options.BinaryLocation = @"C:\Users\mr.315\source\repos\WindowsFormsApp3\WindowsFormsApp3\bin\x64\Debug\cefbased.exe";
        options.AddArgument("debuggerAddress=127.0.0.1:12345");
        options.AddArguments("remote-debugging-port=12345");
        options.DebuggerAddress = "127.0.0.1:"+ portno.ToString();
        ChromeDriver driver = new ChromeDriver(service, options);
        driver.Navigate().GoToUrl("https://google.com");

如果我删除 options.DebuggerAddress = "127.0.0.1:"+ portno.ToString();它打开了我的 cefbased.exe 应用程序,但 chromedriver.exe 有自己的 --port 命令行参数(从任务管理器确认)和 returns 在 60 秒超时用完后出现错误。我遇到了一个与我的非常相似的问题,但代码在 ruby 中,我不知道如何在 C# 中实现它 Chromedriver remote-debugging-port with Selenium

我不知道它是黑客攻击还是合法答案,但我意识到在启用 DebuggerAddress 时,BinaryLocation 中的 exe 将不会执行,唯一的选择是使用端口(可能通过命令行)执行它,然后启动硒。