【问题标题】:Cannot load extension in selenium firefox driver (geckodriver)无法在 selenium firefox 驱动程序 (geckodriver) 中加载扩展
【发布时间】:2019-07-12 12:04:17
【问题描述】:

我手动创建了一个包含插件/扩展(Hotspot Shield VPN 插件)的特定 Firefox 配置文件。现在,在代码中,我通过 firefox 驱动程序加载此配置文件,但问题是从代码启动时未加载扩展。另一方面,手动启动配置文件时它工作得很好。

var profileManager = new FirefoxProfileManager();
var profile = profileManager.GetProfile("brysontiller");
profile.SetPreference("extensions.allowPrivateBrowsingByDefault", true);
profile.SetPreference("extensions.hotspot-shield@anchorfree.com.onByDefault", true);
var options = new FirefoxOptions { Profile = profile, LogLevel = FirefoxDriverLogLevel.Trace };
var driver = new FirefoxDriver(@"C:\Users\danza\source\repos\InstaManager\", options);

driver.Navigate().GoToUrl("https://www.google.com");

我尝试在代码中添加扩展名

profile.AddExtension(@"C:\Users\danza\AppData\Roaming\Mozilla\Firefox\Profiles\652o40ny.profile_7\extensions\hotspot-shield@anchorfree.com.xpi");

这行代码仍然存在上述问题。 (虽然这并不是真正需要的,因为手动创建的配置文件已经包含所需的扩展名,因此无需再次添加)。

我还尝试设置各种配置文件首选项,如下所示:

profile.SetPreference("extensions.allowPrivateBrowsingByDefault", true);
profile.SetPreference("extensions.hotspot-shield@anchorfree.com.onByDefault", true);

问题仍然存在。

当我手动启动配置文件时加载加载项,如下所示:

但是当我通过代码启动它时,它不会:

【问题讨论】:

    标签: c# selenium geckodriver


    【解决方案1】:

    如果您手动创建了配置文件,为什么不尝试直接使用它打开浏览器:

     FirefoxOptions firefoxOptions = new FirefoxOptions();
     firefoxOptions.Profile = new FirefoxProfile("Path to the profile");
     driver = new FirefoxDriver(..., firefoxOptions);
    

    你能告诉我吗?

    【讨论】:

    • 我试过这个,并创建了一个新的配置文件,而不是重定向 Firefox 驱动程序以使用相同的配置文件。上述代码行创建的这个新配置文件中也不存在扩展名。
    猜你喜欢
    • 1970-01-01
    • 2019-01-14
    • 2021-11-27
    • 2019-02-26
    • 2019-12-27
    • 2020-06-16
    • 2018-02-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多