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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛 Bug]: Unable to add cookies in Selenium v4.26.0 #14695

Closed
jeron-kleinfehn-surescripts opened this issue Oct 31, 2024 · 5 comments · Fixed by #14697
Closed

[🐛 Bug]: Unable to add cookies in Selenium v4.26.0 #14695

jeron-kleinfehn-surescripts opened this issue Oct 31, 2024 · 5 comments · Fixed by #14697

Comments

@jeron-kleinfehn-surescripts
Copy link

jeron-kleinfehn-surescripts commented Oct 31, 2024

What happened?

After creating a driver instance, we are unable to add cookies to the driver. Here is a .Net console app that repoduces the issue:

Reference nuget package: PackageReference Include="Selenium.WebDriver" Version="4.26.0"

using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

namespace SeleniumCookies
{
    internal class Program
    {
        static void Main(string[] args)
        {

            List<Cookie> cookies = new List<Cookie>();
            using (IWebDriver driver = new ChromeDriver())
            {
                // Navigate to a webpage
                driver.Navigate().GoToUrl("https://www.google.com");

                cookies = driver.Manage().Cookies.AllCookies.ToList();

                foreach (var cookie in cookies)
                {
                    driver.Manage().Cookies.AddCookie(cookie);
                }

                // Close the browser
                driver.Quit();
            }
        }
    }
}

Note: This only started happening in the Selenium 4.26.0 release. This works fine in the Selenium 4.25.0 release.

How can we reproduce the issue?

You can reproduce the issue by trying to add a cookie to a driver.  See the 'What happened' section for a code snippet.

Relevant log output

Here is the error thrown:

System.NotSupportedException
  HResult=0x80131515
  Message=JsonTypeInfo metadata for type 'OpenQA.Selenium.Internal.ReturnedCookie' was not provided by TypeInfoResolver of type 'OpenQA.Selenium.CommandJsonSerializerContext'. If using source generation, ensure that all root types passed to the serializer have been annotated with 'JsonSerializableAttribute', along with any types that might be serialized polymorphically. The unsupported member type is located on type 'System.Object'. Path: $.
  Source=System.Text.Json
  StackTrace:
   at System.Text.Json.ThrowHelper.ThrowNotSupportedException(WriteStack& state, NotSupportedException ex)
   at System.Text.Json.Serialization.JsonConverter`1.WriteCore(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.Serialize(Utf8JsonWriter writer, T& rootValue, Object rootValueBoxed)
   at System.Text.Json.JsonSerializer.WriteString[TValue](TValue& value, JsonTypeInfo`1 jsonTypeInfo)
   at System.Text.Json.JsonSerializer.Serialize[TValue](TValue value, JsonSerializerOptions options)
   at OpenQA.Selenium.Command.get_ParametersAsJsonString()
   at OpenQA.Selenium.Remote.HttpCommandExecutor.HttpRequestInfo..ctor(Uri serverUri, Command commandToExecute, HttpCommandInfo commandInfo)
   at OpenQA.Selenium.Remote.HttpCommandExecutor.<ExecuteAsync>d__34.MoveNext()
   at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.<ExecuteAsync>d__10.MoveNext()
   at OpenQA.Selenium.WebDriver.<ExecuteAsync>d__63.MoveNext()
   at OpenQA.Selenium.WebDriver.InternalExecute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.CookieJar.AddCookie(Cookie cookie)
   at SeleniumCookies.Program.Main(String[] args) in C:\Users\Jeron.Kleinfehn\source\repos\SeleniumCookies\SeleniumCookies\Program.cs:line 30

  This exception was originally thrown at this call stack:
    [External Code]

Inner Exception 1:
NotSupportedException: JsonTypeInfo metadata for type 'OpenQA.Selenium.Internal.ReturnedCookie' was not provided by TypeInfoResolver of type 'OpenQA.Selenium.CommandJsonSerializerContext'. If using source generation, ensure that all root types passed to the serializer have been annotated with 'JsonSerializableAttribute', along with any types that might be serialized polymorphically.

Operating System

Windows 11

Selenium version

SeleniumVersion=Selenium 4.26.0 | Programming language=.Net/C#

What are the browser(s) and version(s) where you see this issue?

Chrome 130

What are the browser driver(s) and version(s) where you see this issue?

Chrome 130 - Latest ChromeDriver in Selenium 4.26.0 package

Are you using Selenium Grid?

No

Copy link

@jeron-kleinfehn-surescripts, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@RajeshPoola
Copy link

We are also affected by this issue. For now, we have downgraded to the previous version to continue.

@nvborisenko
Copy link
Member

Please check v4.26.1

@RajeshPoola
Copy link

Thank you for the quick turnaround, @nvborisenko. Everything is working fine now.

Copy link

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

@github-actions github-actions bot locked and limited conversation to collaborators Nov 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants