简体   繁体   English

无法在Selenium firefox驱动程序(geckodriver)中加载扩展

[英]Cannot load extension in selenium firefox driver (geckodriver)

I manually created a specific firefox profile containing an add-on/extension (Hotspot Shield VPN add on). 我手动创建了一个包含附件/扩展名(Hotspot Shield VPN附件)的特定Firefox配置文件。 Now, in code I am loading this profile via the firefox driver, however the problem is that the extension is not being loaded when launched from code. 现在,在代码中,我正在通过firefox驱动程序加载此配置文件,但是问题是从代码启动时未加载扩展。 On the other hand it works just fine when launching the profile manually. 另一方面,当手动启动配置文件时,它可以正常工作。

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

I tried adding the extension in code by using 我尝试通过使用代码添加扩展

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

The above problem still persists with this line of code. 上面的问题仍然在此代码行中存在。 (Although this is not really needed as the manually created profile already contains the needed extension so no need to add it again). (尽管实际上并不需要,因为手动创建的配置文件已经包含所需的扩展名,因此无需再次添加它)。

I also tried setting various profile preferences as shown below: 我还尝试设置各种配置文件首选项,如下所示:

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

Problem still persists. 问题仍然存在。

Add-on loads when I launch the profile manually as shown below: 当我手动启动配置文件时,加载项如下所示:

在此处输入图片说明

But when I launch it via code, it does not: 但是,当我通过代码启动它时,它不会:

在此处输入图片说明

If you manually created the profile why don't you try to open the browser using it directly: 如果您手动创建了配置文件,为什么不尝试直接使用它打开浏览器:

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

Could you try and let me know? 你能不能让我知道?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM