4

I have the latest version of Firefox(62.0 32-bit), Selenium(3.14.0.0)and gecko driver(0.22.0 32-bit). I have code as follows:

var firefoxProfile = new FirefoxProfile("XXX");
FirefoxDriverService service = 
    FirefoxDriverService.CreateDefaultService("XXX", "geckodriver.exe");
service.FirefoxBinaryPath = "XXX";
driver = new FirefoxDriver(service, new FirefoxOptions { 
        BrowserExecutableLocation = "XXX", 
        Profile = firefoxProfile, 
        UseLegacyImplementation = false }, 
    new TimeSpan(0, 1, 30));

However the final line fails due to the following error:

System.IO.DirectoryNotFoundException: 'Could not find a part of the path 'C:\Users\XXX\AppData\Local\Temp\anonymous.5bbc89e65ae54c058b27b9027039414b.webdriver-profile.parentlock'.'

When you look in the directory, the "anonymous.5bbc89e65ae54c058b27b9027039414b.webdriver-profile" folder does not exist.

I can generate a folder by invoking the following code:

firefoxProfile.WriteToDisk();

However I'll still get the same error, just with a different "anonymous" folder after running the final line of my code.

I can get around the issue by enabling "UseLegacyImplementation" but this introduces other issues and is not optimal.

Looking around I don't see this message referenced anywhere, there is something referenced on Github, but it's in reference to the profile being ignored, not erroring.

I've had similar code working on older versions of the library and firefox, for some reason when I try to implement on a different machine with all the latest I experience this issue. Does anyone have any input on this?

David Rogers
  • 2,601
  • 4
  • 39
  • 84
  • I noticed that when you instantiate a new FireFoxDriver object you are using a FireFoxDriverService as the first parameter. I see GeckoDriverService being used instead in this documentation: https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/firefox/FirefoxDriver.html. Have you tried using the GeckoDriverService? – RKelley Apr 12 '19 at 19:14
  • @RKelley Maybe in java, but I don't see that exists in the [c# library](https://github.com/SeleniumHQ/selenium/tree/master/dotnet/src/webdriver), that's a good question though, "Selenium.WebDriver.GeckoDriver" is available through NuGet, I think all that does is copy the EXE to the bin directory, examining the "driver" folder under packages confirms my suspicion. The NuGet package is just the EXE. Not sure that is doable in c#. – David Rogers Apr 12 '19 at 21:51
  • Sorry about that. I've been in java world too long. – RKelley Apr 12 '19 at 22:06

1 Answers1

2

I managed to reproduce your problem, but did the following and got rid of it.

  1. I created a new profile from Firefox about:profiles -> New profile Name = TestUser

  2. Copied the location of this profile (Root Directory) and used it when creating the instance of FirefoxProfile

    var firefoxProfile = new FirefoxProfile(@"C:\Users\[user]\AppData\Roaming\Mozilla\Firefox\Profiles\67fkrqcg.TestUser");
    FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(@"C:\geckodriver-v0.22.0-win32", "geckodriver.exe");
    service.FirefoxBinaryPath = @"C:\Program Files\Mozilla Firefox\firefox.exe";
    var driver = new FirefoxDriver(service, new FirefoxOptions
        {
            BrowserExecutableLocation = @"C:\Program Files\Mozilla Firefox\firefox.exe",
            Profile = firefoxProfile,
            UseLegacyImplementation = false
        },
        new TimeSpan(0, 1, 30));
    

The error was thrown due to the method DeleteLockFiles call which according to the documentation Deletes the lock files for a profile.

I suspect you forgot to create the profile and/or did not specify the correct path to it.

David Rogers
  • 2,601
  • 4
  • 39
  • 84
Mihai
  • 371
  • 3
  • 14