geckodriver.exe not in current directory or path variable, Selenium 2.53.1 + Firefox 48 + Selenium 3 Beta

后端 未结 11 966
心在旅途
心在旅途 2020-12-29 22:43

Seen a lot of questions regarding Selenium 2.53.1 and Firefox 47.0.1, but none in regards to the Selenium 3 Beta release. I am attempting to use the new gecko/marionette Fir

相关标签:
11条回答
  • 2020-12-29 23:08

    In your project, click on Tools --> Nuget Package Manager --> Manage NuGet Packages for Solution... The in the open Window Browse Selenium.FireFox.WebDriver Select Project and your project Name and click on install.

    This is the easer form to put the driver on your Selenium Project.

    0 讨论(0)
  • 2020-12-29 23:09

    I would try this:

    1. First, make sure your C# project runs the same .NET framework version as the Client Driver's libraries (when you download them from Selenium HQ, you should see the framework version they're based on). I have 3.5 and 4.0 as of 9/15/2017, so I had to downgrade my C# project to .NET 4.0 to use the 4.0 Client Driver libraries.

    2. In your code, when creating the Firefox Driver Service, make sure you explicitly specify the path to where your geckodriver.exe is located. See how I've added a path parameter to your call to FirefoxDriverService.CreateDefaultService:

      using OpenQA.Selenium.Firefox;
      
      public static class FirefoxInitialise
      {
        private static IWebDriver Driver{get; set;}
        public static IWebDriver Init()
        {
         // I'm assuming your geckodriver.exe is located there:
         // @"C:\MyGeckoDriverExePath\geckodriver.exe"
         FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(@"C:\MyGeckoDriverExePath\");
         service.FirefoxBinaryPath = @"C:\Program Files\Mozilla Firefox\firefox.exe"; // May not be necessary
         FirefoxOptions options = new FirefoxOptions();
         TimeSpan time = TimeSpan.FromSeconds(10);
         Driver = new FirefoxDriver(service, options, time);
         return Driver;
       }
      }
      

    So you can use :

    IWebDriver driver = FirefoxInitialise.Init();
    
    0 讨论(0)
  • 2020-12-29 23:11

    This solution worked for me for VS2017. Just copied the geckodriver.exe to my project folder like this:

    C:\Users\pedne\Desktop\C#\FirstSolution\FirstSolution\bin\Debug

    0 讨论(0)
  • 2020-12-29 23:13

    This solution may helps you fix problem: ( It did help me though)

    public class TestResult {
    
        private IWebDriver driver;
        private StringBuilder verificationErrors;
        private string baseURL;
        private bool acceptNextAlert = true;
    
        [TestInitialize]
        public void SetupTest() {
            FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(@"C:\geckodriver", "geckodriver.exe");
            service.Port = 64444;
            service.FirefoxBinaryPath = @"C:\Program Files (x86)\Firefox Developer Edition\firefox.exe";
            driver = new FirefoxDriver(service);
            baseURL = "http://localhost:49539";
            verificationErrors = new StringBuilder();
        }
    }
    
    REFERENCE
    • Check out @juver-malpartida 's Answer
    0 讨论(0)
  • 2020-12-29 23:17

    This is for who is the begginers ill write the short version in the below after this post :) The easiest way first you need to download all drivers what browser you use and extract all drivers into e.g. C:\Selenium\ there and go to VisualStudio and from here add Selenium packages shown in the pictures Click here in console write this code PM>Install-Package Selenium.WebDriver after that copy your drivers directory and from windows search tab type variables and select (Edit the system environment and variables) shown pic2 in this windows you will have advanced tab at the below click Environment Variables... here you have System variables section find PATH or Path Variable and edit it be careful don't delete it!! next click new - paste directory of drivers and click all windws ok button that's all. restart your VS programm and ckeck it. After this you don't have to add director path into your Constructor like

    IWebDriver driver2 = new InternetExplorerDriver(@"C:\Selenium"); 
    

    One more thing don't forget to import files.

    using OpenQA.Selenium;
    using OpenQA.Selenium.Firefox;
    using OpenQA.Selenium.IE;
    

    For more Advanced IT guys.

    1. Add into Environment Path Yours drivers directory.
    2. VisualStudio install Selenium using NuGet package manager in console mode or how would u like.

      PM> Install-Package Selenium.WebDriver

    3. restart VS.
    0 讨论(0)
提交回复
热议问题