简体   繁体   中英

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). 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. 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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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