Chromedriver 失败 - OpenQA.Selenium.Remote.RemoteNavigator.GoToUrl(String url)

Chromedriver fails - OpenQA.Selenium.Remote.RemoteNavigator.GoToUrl(String url)

我刚刚开始将 C# 与 Selenium 和 XUnit 结合使用。 我只有这个简单的代码来打开 URL 但它总是失败。 这是我的代码:

using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using Xunit;

namespace LearningCSharp
{
    public class FirstTest : IDisposable
    {

        IWebDriver driver = new ChromeDriver();

        [Fact]
        public void ChromeMethod()
        {    
            driver.Navigate().GoToUrl("www.google.com");
            driver.Manage().Window.Maximize();
        }

        public void Dispose()
        {
            try
            {
                driver.Quit();
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception while stopping Chrome..." + e);
            }
        }
    }
}

我在终端执行以下命令:

dotnet test

Chrome 浏览器正常打开,但没有到达 URL 询问就立即关闭。 然后我在 GoToUrl():

行得到以下堆栈跟踪
[xUnit.net 00:00:01.49]
LearningCSharp.FirstTest.ChromeMethod [FAIL]        
X LearningCSharp.FirstTest.ChromeMethod [989ms]                               
Error Message: OpenQA.Selenium.WebDriverException : invalid argument (Session info: chrome=78.0.3904.97)
Stack Trace:
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary 2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.set_Url(String value)
at OpenQA.Selenium.Remote.RemoteNavigator.GoToUrl(String url)

我使用的是 MAC OS 10.14。 Chrome 版本 78。Visual Studio 社区 2019。这是我通过 nuget 使用的包: packages

知道为什么会出现这个错误吗? 谢谢。

您的 URL 无效。在 www 之前添加 https://。这应该可以解决问题。

根据WebDriver specification

If url is not an absolute URL or is not an absolute URL with fragment or not a local scheme, return error with error code invalid argument.