简体   繁体   English

OpenQA.Selenium.WebDriverException Message=无法在 http://localhost:port/ 上通过 C# 中的 Selenium 使用 ChromeDriver Chrome 启动驱动程序服务

[英]OpenQA.Selenium.WebDriverException Message=Cannot start the driver service on http://localhost:port/ using ChromeDriver Chrome through Selenium in C#

I am using latest Selenium.WebDriver NuGet package v3.141.0我正在使用最新的 Selenium.WebDriver NuGet 包 v3.141.0

latest Selenium.WebDriver.ChromeDriver package v80.0.3987.1600最新的 Selenium.WebDriver.ChromeDriver 包 v80.0.3987.1600

my chrome version is 80.0.3987.87我的 chrome 版本是 80.0.3987.87

the chromedriver.exe is in the same folder as my program executable chromedriver.exe 与我的程序可执行文件位于同一文件夹中

var driver = new ChromeDriver();
driver.Navigate().GoToUrl("https://www.google.com/");
Starting ChromeDriver 80.0.3987.16 (320f6526c1632ad4f205ebce69b99a062ed78647-refs/branch-heads/3987@{#185}) on port #
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
The remote server returned an error: (404) Not Found.
The remote server returned an error: (404) Not Found.
The remote server returned an error: (404) Not Found.
The remote server returned an error: (404) Not Found.
The remote server returned an error: (404) Not Found.
The remote server returned an error: (404) Not Found.
The remote server returned an error: (404) Not Found.
The remote server returned an error: (404) Not Found.
The remote server returned an error: (404) Not Found.
The remote server returned an error: (404) Not Found.
The remote server returned an error: (404) Not Found.
The remote server returned an error: (404) Not Found.
The remote server returned an error: (404) Not Found.
The remote server returned an error: (404) Not Found.

followed by the whole stacktrace -其次是整个堆栈跟踪 -

OpenQA.Selenium.WebDriverException
  HResult=0x80131500
  Message=Cannot start the driver service on http://localhost:port/
  Source=WebDriver
  StackTrace:
   at OpenQA.Selenium.DriverService.Start()
   at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
   at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
   at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout)
   at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeOptions options)
   at OpenQA.Selenium.Chrome.ChromeDriver..ctor()
   at snow_net.Program.create_chg_mypruit() in C:\Users\username\source\repos\snow-net\Program.cs:line 119
   at snow_net.Program.Main(String[] args) in C:\Users\username\source\repos\snow-net\Program.cs:line 66

edit: i have also tried编辑:我也试过

IWebDriver driver;
            using (driver = new ChromeDriver())
            {
                driver.Navigate().GoToUrl(@"https://www.google.com/");
            }

which fails with the same error and tried the IE and Firefox drivers as well失败并出现相同的错误并尝试了 IE 和 Firefox 驱动程序

Update:更新:

So i tried this at home (not on my companies network) and it worked with this exact code... am i being blocked by firewall ?所以我在家里(不是在我公司的网络上)尝试了这个,它使用了这个确切的代码......我被防火墙阻止了吗?

You have to take care of a few things:您必须注意以下几点:

  • You need to pass the entire url , ie add www to https://google.com , so effectively the url will be https://www.google.com/ .您需要传递整个url ,即将www添加到https://google.com ,因此有效的url将是https://www.google.com/
  • Additionally, as you have initialized the instance of ChromeDriver as driver , you have to invoke Navigate() with the driver instance only, but not with drive .此外,由于您已将ChromeDriver的实例初始化为driver ,因此您必须仅使用驱动程序实例调用Navigate() ,而不是使用drive
  • Effectively your code block will be:实际上,您的代码块将是:

     var driver = new ChromeDriver(); driver.Navigate().GoToUrl("https://www.google.com/");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 OpenQA.Selenium.WebDriverException: '无法在 http://localhost:60623/ 上启动驱动程序服务' - OpenQA.Selenium.WebDriverException: 'Cannot start the driver service on http://localhost:60623/' OpenQA.Selenium.WebDriverException:“无法在 http://localhost:20548/ 上启动驱动程序服务” - OpenQA.Selenium.WebDriverException: 'Cannot start the driver service on http://localhost:20548/' OpenQA.Selenium.WebDriverException:'未知错误:ChromeDriver 仅支持 BMP 中的字符,同时通过 C# Selenium 发送表情符号 - OpenQA.Selenium.WebDriverException: 'unknown error: ChromeDriver only supports characters in the BMP while sending an emoji through C# Selenium OpenQA.Selenium.WebDriverException - OpenQA.Selenium.WebDriverException c# OpenQA.Selenium.WebDriverException:对于 chromedriver.exe(nuget pkg 版本 2.46.0) - c# OpenQA.Selenium.WebDriverException : for chromedriver.exe (nuget pkg version 2.46.0) OpenQA.Selenium.WebDriverException:未知错误:a.tagName.toUpperCase 不是通过 Selenium 和 C# 带有 reactJS 元素的函数 - OpenQA.Selenium.WebDriverException : unknown error: a.tagName.toUpperCase is not a function with reactJS elements through Selenium and C# OpenQA.Selenium.WebDriverException: '不能点击元素' - OpenQA.Selenium.WebDriverException: 'Cannot click on element' C# OpenQA.Selenium.WebDriverException:“未知错误:无法创建 Chrome 进程。” - C# OpenQA.Selenium.WebDriverException: 'unknown error: Failed to create Chrome process.' OpenQA.Selenium.WebDriverException:未知错误:Chrome 无法启动:通过 Selenium 执行测试时异常退出 start on linux - OpenQA.Selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally while executing tests through Selenium start on linux 异常:OpenQA.Selenium.WebDriverException: - Exception :OpenQA.Selenium.WebDriverException:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM