Robert
Robert

Reputation: 10943

C# selenium webdriver raise InvalidOperationException ocurred in WebDriver.dll

I am trying to use the selenium driver for automation test.

I have installed this NuGet Packages:

enter image description here

My simple code and the error:

enter image description here

It is my project structure with the references:

enter image description here

I don't know what or where the problem is?

More info

View Detail...

There is the View Detail... from the error System.InvalidOperationException:

enter image description here

And the Stack Trace message:

   at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
   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 SeleniumFirst.Program.Main(String[] args) in c:\Users\roberto.cardenas\Documents\Visual Studio 2013\Projects\SeleniumFirst\SeleniumFirst\Program.cs:line 17
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

Upvotes: 0

Views: 7689

Answers (3)

Robert
Robert

Reputation: 10943

Ok the problem was with the chromedriver.exe file. I installed the version 2.10 using the NuGet Packages Manager but I was reading this post and I did the steps. But in case to avoid an answer with a broken link for the post there is the solution:

So, to resolve this problem you can just navigate to http://chromedriver.storage.googleapis.com/index.html and download last stable version:

enter image description here

In my case was 2.20 so I navigate to: http://chromedriver.storage.googleapis.com/index.html?path=2.20/

enter image description here

Later I copied this driver version to C: directory and create a path to the driver:

class Program
{
    static void Main(string[] args)
    {
        string DRIVER_PATH = @"C:\";
        //create a reference to our browser
        IWebDriver chrome = new ChromeDriver(DRIVER_PATH);

        //navigate to google page
        chrome.Navigate().GoToUrl("http://www.google.com");

        IWebElement search = chrome.FindElement(By.Name("q"));

        search.SendKeys("executeautomation");
    }
}

And everything is ok.

Upvotes: 0

Vitalii
Vitalii

Reputation: 86

Looks like you need to update chrome driver. Here is a bug https://bugs.chromium.org/p/chromedriver/issues/detail?id=1257 The latest version is 2.21

Upvotes: 1

Striter Alfa
Striter Alfa

Reputation: 1577

chromedriver.exe needs to be inside the aplication dir and with propriet output as "copy always".

Other way is send a path to chromedriver constructor when you create the object. This allow you put all drivers inside a dir in the current project. As example:

var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\Drivers";
var chromeDriver = new ChromeDriver(path);

// It will search in "[...]bin\Debug[or Release]\Drivers\chromedriver.exe"

Upvotes: 2

Related Questions