26

Pracuję nad strukturą Automation przy użyciu WebDriver z C#. Działa dobrze z Firefoksem, ale nie z IE.Błąd "IEDriverServer nie istnieje" podczas uruchamiania testu Selenium za pomocą C# w Windows 7

otrzymuję następujący błąd:

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

używam IE 9 i 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(); 

Zobacz również this screenshot.

+0

Po prostu skopiuj go do katalogu wyjściowego Bin \ Debug, jeśli jeszcze tam nie jest. –

Odpowiedz

11

Per Jim Evans (który działa na 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.

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

+0

Czy możesz mi pomóc z próbką kodu, jak powiązać IEDriverServer.exe za pomocą C#. Jest to w ten sposób System.Environment.SetEnvironmentVariable ("webdriver.ie.driver", "D: // Software 4.0azriverServer.exe") ; Sterownik IWebDriver = nowy InternetExplorerDriver(); – Pat

+0

Nie pracowałem w wiązaniach C#. Jednak jednym ze sposobów rozwiązania tego kodu zewnętrznego jest przekazanie tej zmiennej podczas uruchamiania selenowego słoika. Podobnie jak java -jar selenium-server.jar -Dwebdriver.ie.driver = "D: // Software 4.0tyriverServer.exe" –

+0

Istnieją nieoficjalne pakiety NuGet dla [Chrome] (https://www.nuget.org/ pakiety/Selenium.WebDriver.ChromeDriver /) i [IE] (https://www.nuget.org/packages/Selenium.WebDriver.IEDriver/); dodają sterowniki do katalogu paczek, dodają do nich linki do projektu testowego i ustaw "kopiuj, jeśli nowsze". Następnie po prostu wywołaj przeciążenia konstruktora, przekazując "." dla bieżącego katalogu * (z powodu powyższego problemu% PATH%) *; np .: 'ScenarioContext.Current [" browser "] = new ChromeDriver (". ");' W [NCrunch] (http://www.ncrunch.net/) nie musiałem go konfigurować, aby kopiować pliki albo . – Damon

1

Jeśli pracujesz z Visual Studio i C# Mam zaktualizowaną paczkę Nuget NareshScaler aby automatycznie zainstalować IEDriverServer, ChromeDriver etc , co oznacza, że ​​możesz szybciej zacząć działać.

http://nuget.org/packages/NareshScaler

+0

Czy możesz mi pomóc to zrobić bez użycia pakietu NareshScaler przy użyciu kodu C# – Pat

16

Oto prosty przykład C# jak wywołać InternetExplorerDriver pomocą IEDriverServer.exe.

Refactor według twoich potrzeb.

Uwaga: użycie driver.Quit() zapewnia, że ​​proces IEDriverServer.exe zostanie zamknięty po zakończeniu testu.

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 
     } 
    } 
} 
+1

Dzięki Ralp .. Teraz działa dobrze. – Pat

20

The IEDriverServer.exe (jak również ChromeDriver.exe) można pobrać ze strony:

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

Aby to zadziałało z testami Selenium, dołącz plik .exe do projektu testowego i ustaw jego właściwości na "Kopiuj zawsze".

UWAGA: Będziesz musiał dostosować okno dialogowe Dodaj plik, aby wyświetlić pliki .exe.

Wykonanie tej czynności spowoduje usunięcie błędu.

0
 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; 
    } 
1

Kod dla WebDriver używający java do uruchamiania z IE. Wierzę, że ta koncepcja może być pomocne, przy użyciu 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); 

Jeżeli powyższy kod nie działa użyć następujących zamiast "pliku file = new File (" C: \ Program Files \ Internet Explorer \ IEXPLORE. exe ");":

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

[Uwaga: wersja IEDriverServer i Windows (32 lub 64 bit) może się różnić w poszczególnych osób]

+0

Pobrałem "IEDriverServer_Win32_2.31.0.zip". Według twojego przewodnika to działa dobrze. Dzięki Ripon –

+0

@ user2027659: To moja przyjemność –

1

Podaj ścieżkę do folderu, w którym tylko Internetexplorer.exe znajduje.

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(); 
    } 
} } 
+0

Cześć Nithin i witam na stronie. Czy możesz rozważyć rozszerzenie odpowiedzi, aby była ona bardziej kompletna? Istnieje przewodnik dobrych odpowiedzi [tutaj] (http://stackoverflow.com/help/how-to-answer) - generalnie wolimy nieco więcej wyjaśnień niż jednolinijkowa odpowiedź. – starsplusplus

Powiązane problemy