Benoit
Benoit

Reputation: 3

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

I have just started using C# with Selenium and XUnit. I just have this simple code to open a URL but it keeps failing. Here is my code:

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);
            }
        }
    }
}

I execute the following command in the terminal :

dotnet test

Chrome browser opens properly but closes immediately without getting to the URL asked. Then i get the following stack trace at the line with 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)

I'm using a MAC OS 10.14. Chrome version 78. Visual Studio Community 2019. And here are the packages I'm using via nuget: packages

Any idea why this error ? Thank you.

Upvotes: 0

Views: 1759

Answers (1)

Alexey R.
Alexey R.

Reputation: 8686

Your URL is not valid. Add https:// before www. This should solve the problem.

As per 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.

Upvotes: 4

Related Questions