OpenQA.Selenium.WebDriverException Message=无法在 http://localh



>我正在使用最新的Selenium.WebDriver NuGet包v3.141.0

最新的Selenium.WebDriver.ChromeDriver软件包v80.0.3987.1600

我的Chrome版本是80.0.3987.87

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.

后跟整个堆栈跟踪 -

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:Usersusernamesourcerepossnow-netProgram.cs:line 119
at snow_net.Program.Main(String[] args) in C:Usersusernamesourcerepossnow-netProgram.cs:line 66

编辑: 我也试过

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

失败并出现相同的错误,并尝试了IE和Firefox驱动程序

更新:

所以我在家里(不是在我的公司网络上(尝试了这个,它适用于这个确切的代码......我被防火墙阻止了吗?

你必须处理几件事:

  • 您需要传递整个url,即将www添加到https://google.com中,因此有效地将urlhttps://www.google.com/
  • 此外,由于您已将ChromeDriver的实例初始化为driver,因此您必须仅使用驱动程序实例调用Navigate(),而不能使用drive调用。
  • 实际上,您的代码块将是:

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

相关内容

  • 没有找到相关文章

最新更新