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

后端 未结 11 1003
心在旅途
心在旅途 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: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();
    

提交回复
热议问题