Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

C#: Unable to add firefox extension #7909

Closed
prasanth-G24 opened this issue Jan 3, 2020 · 8 comments
Closed

C#: Unable to add firefox extension #7909

prasanth-G24 opened this issue Jan 3, 2020 · 8 comments

Comments

@prasanth-G24
Copy link

prasanth-G24 commented Jan 3, 2020

馃悰 Bug Report

To Reproduce

using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Remote;

namespace sel_cs
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            IWebDriver driver = null;
            try
            {
                FirefoxOptions options = new FirefoxOptions();
                FirefoxProfile profile = new FirefoxProfile();
                profile.AddExtension("/path/to/firefox-ext.xpi");
                options.Profile = profile;
                ICapabilities capabilities = options.ToCapabilities();
                driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), capabilities);
                driver.Navigate().GoToUrl("http://www.google.com");
                Console.WriteLine("hello");
                driver.Quit();
            }
            catch(Exception e)
            {
                Console.Write(e);
            }
        }
    }
}

Detailed steps to reproduce the behavior:

  1. Create/ download any .xpi file
  2. Make sure the xpi is working
  3. Replace the path to .xpi file given in the program with the path to xpi in your machine

Expected behavior

A "hello" getting printed in my console

Actual behavior

I am getting the exception:

System.ArgumentOutOfRangeException: Year, Month, and Day parameters describe an un-representable DateTime.
  at System.DateTime.DateToTicks (System.Int32 year, System.Int32 month, System.Int32 day) [0x0006c] in <d2ec5c92492f4d6ba8c422bdf574b786>:0 
  at System.DateTime..ctor (System.Int32 year, System.Int32 month, System.Int32 day, System.Int32 hour, System.Int32 minute, System.Int32 second) [0x00000] in <d2ec5c92492f4d6ba8c422bdf574b786>:0 
  at System.IO.Compression.ZipStorer.DosTimeToDateTime (System.UInt32 dosTime) [0x00000] in <19027cc8501444099501b87290061165>:0 
  at System.IO.Compression.ZipStorer.ReadCentralDirectory () [0x00167] in <19027cc8501444099501b87290061165>:0 
  at OpenQA.Selenium.Firefox.FirefoxExtension.Install (System.String profileDirectory) [0x00063] in <19027cc8501444099501b87290061165>:0 
  at OpenQA.Selenium.Firefox.FirefoxProfile.InstallExtensions () [0x00027] in <19027cc8501444099501b87290061165>:0 
  at OpenQA.Selenium.Firefox.FirefoxProfile.WriteToDisk () [0x00038] in <19027cc8501444099501b87290061165>:0 
  at OpenQA.Selenium.Firefox.FirefoxProfile.ToBase64String () [0x00006] in <19027cc8501444099501b87290061165>:0 
  at OpenQA.Selenium.Firefox.FirefoxOptions.GenerateFirefoxOptionsDictionary () [0x00019] in <19027cc8501444099501b87290061165>:0 
  at OpenQA.Selenium.Firefox.FirefoxOptions.ToCapabilities () [0x00015] in <19027cc8501444099501b87290061165>:0 
  at sel_cs.MainClass.Main (System.String[] args) [0x00057] in /home/local/prasanth/Projects/sel_cs/sel_cs/Program.cs:20

Environment

OS: Ubuntu 18.04
Browser: Firefox
Browser version: 70.0
Gechodriver version: >= 0.24.0
Language Bindings version: WebDriver.dll (.NET 4.5, Version: 3.141.0)
Selenium Grid version (if applicable): 3.9.1

@ghost ghost added the needs-triaging label Jan 3, 2020
@prasanth-G24
Copy link
Author

Has anyone looked into this bug? Any updates?

@fraser-lowndes
Copy link

Also affecting me. Seems like this was fixed in ZipStorer 3.5.2 (latest is 3.6.0). Though from what I can see the library is copied in (https://github.com/SeleniumHQ/selenium/blob/master/third_party/dotnet/ZipStorer/ZipStorer.cs) instead of being retrieved via NuGet.

@jimevans Is it possible to update the copied ZipStorer with the latest version, or use the NuGet package?

@jimevans
Copy link
Member

The ZipStorer code in question is no longer used in the project. It鈥檚 also important to note that the Selenium project does not take new .NET dependencies lightly, that when the ZipStorer classes were added to the project years ago, no such NuGet package existed.

@prasanth-G24
Copy link
Author

@jimevans I have not used any zip storer in my code. I don't understand your solution. Looks like the webdriver.dll which I mentioned in my question is the latest one. Can you please explain a bit further?

@jimevans
Copy link
Member

@prasanth-G24 The ZipStorer class mentioned is used internally by 3.x versions of the .MET bindings for handling Firefox extensions. It is not used by your code. That library is used because .NET 3.5 and .NET 4.0 do not have full native support for ZIP files. Since Selenium 4.0 (currently available as a pre-release library) requires .NET 4.5 or above, which does have full ZIP file support, Selenium no longer requires the ZipStorer class, and that class has been removed from the source tree.

@prasanth-G24
Copy link
Author

prasanth-G24 commented Jan 24, 2020

@jimevans I understand it is not possible to do what I am trying to do, with selenium 3.x versions. However I tried to do the same thing with a few modifications, using the selenium 2.53.dll, and I am getting the exact error. What is the fix for this? The problem is, my authorities don't want me to use a pre-released library.

DesiredCapabilities caps = DesiredCapabilities.Firefox();
FirefoxProfile profile = new FirefoxProfile();
profile.AddExtension("/home/local/prasanth-8508/firefox-ext.xpi");
caps.SetCapability("firefox_profile", profile.ToBase64String());
this.driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), caps); 

@jimevans
Copy link
Member

Since the code for extracting ZIP files did not change between 2.x and 3.x, I鈥檓 entirely unsurprised that the same issue occurs with the 2.x assembly. The only available solution is to move to the 4.0 alpha releases.

@lock
Copy link

lock bot commented Feb 23, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Feb 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants