How to instantiate InternetExplorerDriver with Selenium WebDriver using C#

Amar HR picture Amar HR · Mar 6, 2013 · Viewed 20.9k times · Source
new InternetExplorerDriver();

But I could see exception as below:

OpenQA.Selenium.DriverServiceNotFoundException was unhandled by user code
  HResult=-2146233088
  Message=The IEDriverServer.exe file does not exist in the current directory or in a directory on the PATH environment variable. The driver can be downloaded at http://code.google.com/p/selenium/downloads/list.
  Source=WebDriver
  StackTrace:
       at OpenQA.Selenium.DriverService.FindDriverServiceExecutable(String executableName, Uri downloadUrl)
       at OpenQA.Selenium.IE.InternetExplorerDriverService.CreateDefaultService()
       at OpenQA.Selenium.IE.InternetExplorerDriver..ctor(InternetExplorerOptions options)
       at OpenQA.Selenium.IE.InternetExplorerDriver..ctor()
       at Accelrys.CommonTestFramework.WebActions.WebActionLibrary.CreateSeleniumDriver()

Answer

Hemanth picture Hemanth · Mar 6, 2013

Add these lines to your code before creating the object.

   System.setProperty("webdriver.ie.driver", 
        "E:\\path where your IEDriverServer is located\\IEDriverServer.exe");

You can download IEDriverServer.exe file from here.

As you are using C# you can use the below code.

private const string IE_DRIVER_PATH = @"C:\PathTo\IEDriverServer";
var driver = new InternetExplorerDriver(IE_DRIVER_PATH, options);