在 Windows 7 中使用 C# 运行 Selenium 测试期间出现“IEDriverServer 不存在”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11010317/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 16:05:50  来源:igfitidea点击:

"IEDriverServer does not exist" error during running Selenium test with C# in Windows 7

c#internet-explorerwindows-7selenium-webdriverselenium-rc

提问by Pat

I'm working on Automation framework using WebDriver with C#. Its working fine with Firefox but not with IE.

我正在使用带有 C# 的 WebDriver 开发自动化框架。它适用于 Firefox,但不适用于 IE。

I am getting the following error:

我收到以下错误:

IEDriverServer.exe does not exist-The file c:\users\administrator\documents\visual studio 2010\projects\TestProject1\TestProject1\bin\Debug\IEDriverServer.exe does not exist. The driver can be downloaded at http://code.google.com/p/selenium/downloads/list

IEDriverServer.exe 不存在 - 文件 c:\users\administrator\documents\visual studio 2010\projects\TestProject1\TestProject1\bin\Debug\IEDriverServer.exe 不存在。驱动程序可以在http://code.google.com/p/selenium/downloads/list下载

I am using IE 9 and Windows 7.

我正在使用 IE 9 和 Windows 7。

IWebDriver driver = new InternetExplorerDriver();
driver.Navigate().GoToUrl("http://www.google.co.uk");
IWebElement queryBox = driver.FindElement(By.Name("q"));
queryBox.SendKeys("The Automated Tester");
queryBox.SendKeys(Keys.ArrowDown);
queryBox.Submit();

See also this screenshot.

另见这个截图

采纳答案by A.J

Per Jim Evans (who works on IEDriverServer)

Per Jim Evans(在 IEDriverServer 上工作)

The .NET bindings don't scan the %PATH% environment variable for the executable. That means for the .NET bindings only, the IEDriverServer.exe is expected to either be found in the same directory as the .NET bindings assembly, or you must specify the directory where it can be found in the constructor to the InternetExplorerDriver class.

Failure to do one of these things (or to set the UseInternalServer property in the InternetExplorerOptions class) will cause the .NET IE driver implementation to throw an exception. This is strictly by design, as we want people to begin using the standalone IEDriverServer.exe, and the ability to use an "internal" or "legacy" version of the server will be removed in a future release.

.NET 绑定不会扫描可执行文件的 %PATH% 环境变量。这意味着对于 .NET 绑定,IEDriverServer.exe 应该与 .NET 绑定程序集位于同一目录中,或者您必须指定可以在 InternetExplorerDriver 类的构造函数中找到它的目录。

未能执行其中一项操作(或在 InternetExplorerOptions 类中设置 UseInternalServer 属性)将导致 .NET IE 驱动程序实现抛出异常。这完全是设计使然,因为我们希望人们开始使用独立的 IEDriverServer.exe,并且在未来版本中将删除使用“内部”或“传统”版本服务器的能力。

https://groups.google.com/forum/?fromgroups#!topic/webdriver/EvTyEPYchxE

https://groups.google.com/forum/?fromgroups#!topic/webdriver/EvTyEPYchxE

回答by Iain Hunter

If you're working with Visual Studio and C# I've updated my NareshScaler nuget package to install IEDriverServer, ChromeDriver etc automatically, meaning you can get up and running quicker.

如果您正在使用 Visual Studio 和 C#,我已经更新了我的 NareshScaler nuget 包以自动安装 IEDriverServer、ChromeDriver 等,这意味着您可以更快地启动和运行。

http://nuget.org/packages/NareshScaler

http://nuget.org/packages/NareshScaler

回答by Ralph Willgoss

Here's a simple C# example of how to call the InternetExplorerDriverusing the IEDriverServer.exe.

下面是一个简单的 C# 示例,说明如何InternetExplorerDriver使用 IEDriverServer.exe调用。

Refactor according to your needs.

根据您的需要重构。

Note:the use of driver.Quit()which ensures that the IEDriverServer.exe process is closed, after the test has finished.

注意:使用driver.Quit()which 可确保在测试完成后关闭 IEDriverServer.exe 进程。

using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.IE;

namespace SeleniumTest
{
    [TestClass]
    public class IEDriverTest
    {
        private const string URL = "http://url";
        private const string IE_DRIVER_PATH = @"C:\PathTo\IEDriverServer.exe";

        [TestMethod]
        public void Test()
        {
            var options = new InternetExplorerOptions()
            {
                InitialBrowserUrl = URL,
                IntroduceInstabilityByIgnoringProtectedModeSettings = true
            };
            var driver = new InternetExplorerDriver(IE_DRIVER_PATH, options);
            driver.Navigate();
            driver.Close(); // closes browser
            driver.Quit(); // closes IEDriverServer process
        }
    }
}

回答by Peter Bernier

The IEDriverServer.exe (as well as ChromeDriver.exe) can be downloaded from:

IEDriverServer.exe(以及 ChromeDriver.exe)可以从以下位置下载:

http://selenium-release.storage.googleapis.com/index.html.

http://selenium-release.storage.googleapis.com/index.html

To get these to work with your Selenium tests, include the .exe in your test project, and set its properties to 'Copy Always'.

要使这些与您的 Selenium 测试一起使用,请将 .exe 包含在您的测试项目中,并将其属性设置为“始终复制”。

NOTE: You'll have to adjust the Add File dialog to display .exe files.

注意:您必须调整“添加文件”对话框以显示 .exe 文件。

Doing this will resolve the error.

这样做将解决错误。

回答by Pat

      public IWebDriver IEWebDriver()
    {
        var options = new InternetExplorerOptions();
        options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
        webDriver = new   InternetExplorerDriver(ConfigurationSettings.AppSettings["IDEServerPath"].ToString(), options);//Path of ur IE WebDriver,Here I stored it in a AppConfig File
        return webDriver;
   }

回答by Ripon Al Wasim

Code for WebDriver using java to run with IE. I believe this concept might be helpful for you using C#:

WebDriver 使用 java 与 IE 一起运行的代码。我相信这个概念可能对你使用 C# 有帮助:

DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);      
File file = new File("C:\Program Files\Internet Explorer\iexplore.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
driver = new InternetExplorerDriver(capabilities);

If above code doesn't work use the following instead of "File file = new File("C:\Program Files\Internet Explorer\iexplore.exe");":

如果上述代码不起作用,请使用以下代码代替“File file = new File("C:\Program Files\Internet Explorer\iexplore.exe");”:

File file = new File("F:\Ripon\IEDriverServer_Win32_2.25.2\IEDriverServer.exe");

[Note: The version of IEDriverServer and Windows (32 or 64 bit) may vary individual to individual]

[注意:IEDriverServer 和 Windows(32 或 64 位)的版本可能因人而异]

回答by Nithin Sasalu

Give path only till folder where Internetexplorer.exe is located.

仅给出 Internetexplorer.exe 所在文件夹的路径。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using System.IO;

namespace Automation
  {
    class To_Run_IE
     {
        static void Main(string[] args)
        {
         //Keep Internetexplorer.exe in "D:\Automation\Internetexplorer.exe"
          IWebDriver driver = new InternetExplorerDriver(@"D:\Automation\"); \Give path till the exe folder
         //IWebDriver driver = new Firefoxdriver()
       driver.Navigate().GoToUrl("http://www.google.com/");
       driver.Manage().Window.Maximize();         
       IWebElement query = driver.FindElement(By.Name("q"));
       query.SendKeys("Cheese");        
       query.Submit();         
       System.Console.WriteLine("Page title is: " + driver.Title);
       driver.Quit();
    }
} }