Selenium Firefox驱动程序 - 由于“DirectoryNotFoundException”而无法加载FirefoxProfile

问题描述 投票:4回答:1

我有最新版本的Firefox(62.0 32位),Selenium(3.14.0.0)和gecko驱动程序(0.22.0 32位)。我的代码如下:

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));

但是,由于以下错误,最后一行失败:

System.IO.DirectoryNotFoundException:'找不到路径的一部分'C:\ Users \ XXX \ AppData \ Local \ Temp \ anonymous.5bbc89e65ae54c058b27b9027039414b.webdriver-profile.parentlock'。'

当您查看目录时,“anonymous.5bbc89e65ae54c058b27b9027039414b.webdriver-profile”文件夹不存在。

我可以通过调用以下代码生成一个文件夹:

firefoxProfile.WriteToDisk();

但是,在运行代码的最后一行后,我仍然会得到相同的错误,只是使用不同的“匿名”文件夹。

我可以通过启用“UseLegacyImplementation”来解决这个问题,但这会引入其他问题并且不是最佳选择。

环顾四周,我没有看到这个消息在任何地方引用,在Github上引用了一些内容,但是它引用了被忽略的配置文件,而不是错误。

我有类似的代码在旧版本的库和firefox上工作,出于某种原因,当我尝试在不同的机器上实现所有最新的我遇到此问题。有人对此有任何意见吗?

c# selenium firefox selenium-webdriver selenium-firefoxdriver
1个回答
2
投票

我设法重现你的问题,但做了以下并摆脱它。

  1. 我从Firefox about:profiles创建了一个新的配置文件 - >新配置文件Name = TestUser
  2. 复制此配置文件的位置(根目录)并在创建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));

由于根据DeleteLockFiles删除了配置文件的锁定文件的方法documentation调用,引发了错误。

我怀疑您忘记创建配置文件和/或没有指定正确的路径。

© www.soinside.com 2019 - 2024. All rights reserved.