如何使用C#使用Selenium WebDriver实例化InternetExplorerDriver

Ama*_* HR 9 c# selenium selenium-webdriver remotewebdriver iedriverserver

new InternetExplorerDriver();
Run Code Online (Sandbox Code Playgroud)

但我可以看到异常如下:

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()
Run Code Online (Sandbox Code Playgroud)

Hem*_*nth 9

在创建对象之前,将这些行添加到代码中.

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

您可以从这里下载IEDriverServer.exe文件.

在使用C#时,您可以使用以下代码.

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


abh*_*nav 7

正如例外所述,您需要根据您拥有的IE下载32位或64位IEDriverServer,并确保它在我们的路径中可用.也就是说,当您在命令行上键入IEDriverServer.exe时,它应该被解析.试试吧