在Windows 7中使用C#运行Selenium测试时出现“IEDriverServer不存在”错误
我正在使用带有C#的WebDriver开发Automation框架。 它与Firefox一起工作正常,但不适用于IE。
我收到以下错误:
IEDriverServer.exe不存在 – 文件c:\ users \ administrator \ documents \ visual studio 2010 \ projects \ TestProject1 \ TestProject1 \ _bin \ Debug \ IEDriverServer.exe不存在。 该驱动程序可以从http://code.google.com/p/selenium/downloads/list下载
我使用的是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();
也可以看看 。
Per Jim Evans(曾在IEDriverServer工作)
.NET绑定不扫描可执行文件的%PATH%环境变量。 这意味着仅对于.NET绑定,IEDriverServer.exe应该与.NET绑定程序集位于同一目录中,或者必须指定在InternetExplorerDriver类的构造函数中可以找到它的目录。
如果不执行这些操作之一(或在InternetExplorerOptions类中设置UseInternalServer属性)将导致.NET IE驱动程序实现抛出exception。 这是严格按照设计进行的,因为我们希望人们开始使用独立的IEDriverServer.exe,并且在将来的版本中将删除使用服务器的“内部”或“遗留”版本的function。
https://groups.google.com/forum/?fromgroups#!topic/webdriver/EvTyEPYchxE
可以从以下位置下载IEDriverServer.exe(以及ChromeDriver.exe):
http://selenium-release.storage.googleapis.com/index.html 。
要使这些与Selenium测试一起使用,请在测试项目中包含.exe,并将其属性设置为“始终复制”。
注意:您必须调整“添加文件”对话框以显示.exe文件。
这样做可以解决错误。
这是一个简单的C#示例,说明如何使用IEDriverServer.exe调用InternetExplorerDriver
。
根据您的需求重构。
注意:使用driver.Quit()
确保在测试完成后关闭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 } } }
如果您正在使用Visual Studio和C#,我已经更新了我的NareshScaler nuget包以自动安装IEDriverServer,ChromeDriver等,这意味着您可以更快地启动和运行。
使用java与IE一起运行的WebDriver代码。 我相信这个概念可能对你使用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);
如果上面的代码不起作用,请使用以下代码“File file = new File(”C:\ Program Files \ Internet Explorer \ iexplore.exe“);”:
File file = new File("F:\\Ripon\\IEDriverServer_Win32_2.25.2\\IEDriverServer.exe");
[注意:IEDriverServer和Windows(32或64位)的版本可能因人而异]
仅提供路径直到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\32\Internetexplorer.exe" IWebDriver driver = new InternetExplorerDriver(@"D:\Automation\32\"); \\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(); } } }
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; }