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

[馃悰 Bug]: Delete Cookies removes all cookies with the same name instead of deleting a provided Cookie #13840

Closed
dmitryyukhnovets opened this issue Apr 18, 2024 · 5 comments
Labels
G-w3c Requires change to W3C Spec
Milestone

Comments

@dmitryyukhnovets
Copy link

What happened?

RemoteWebDriver class has the following method:

 public void deleteCookie(Cookie cookie) {
            this.deleteCookieNamed(cookie.getName());
        }

It means that cookies are deleted by name, so if we have two cookies with the same name (but different other attributes) - we cannot remove only one of them.

WebDriver version 4.17.0
Browser Chrome
To reproduce the issue please see the code below.

How can we reproduce the issue?

public static void main(String[] args) {

		ChromeDriver driver = new ChromeDriver();
		driver.get("https://google.com");
		int defaultCookiesSize = driver.manage().getCookies().size();
		System.out.println("Default cookies size :" + defaultCookiesSize);
		driver.manage().addCookie(new Cookie("test", "test"));
		System.out.println("Add one cookie:" + driver.manage().getCookies().size());
		Calendar c = Calendar.getInstance();
		c.add(Calendar.DAY_OF_YEAR, 2);
		Date date = c.getTime();
		Cookie cookie2 = new Cookie("test", "test2", "google.com", "/",date, true);
		driver.manage().addCookie(cookie2);
		System.out.println("Add another cookie:" + driver.manage().getCookies().size());
		Set<Cookie> cookies = driver.manage().getCookies();
		for (Cookie cookie : cookies) {
			if (cookie.getValue().equals("test2")){
				driver.manage().deleteCookie(cookie);
				System.out.println("Removed one cookie");
			}
		}
		int actualCookieSize = driver.manage().getCookies().size();
		System.out.println("Finally :" + actualCookieSize);
		System.out.println(actualCookieSize == defaultCookiesSize + 1);
		driver.quit();
	}

Relevant log output

Default cookies size :2
Add one cookie:3
Add another cookie:4
Removed one cookie
Finally :2
false

Operating System

MacOs

Selenium version

Java 17

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

Chrome 123.0.6312.124

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

The chromedriver version (122.0.6261.128)

Are you using Selenium Grid?

no

Copy link

@dmitryyukhnovets, 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!

@diemol diemol added this to the 4.21 milestone Apr 30, 2024
@pujagani pujagani added the C-java label May 6, 2024
@pujagani
Copy link
Contributor

pujagani commented May 6, 2024

Hello! Thank you for sharing the details.
I am not sure this is possible with W3C WebDriver specification https://www.w3.org/TR/webdriver2/#delete-cookie. I think this is possible in Selenium 5, using the W3C WebDriver BiDi specification https://w3c.github.io/webdriver-bidi/#command-storage-deleteCookies.

@diemol
Copy link
Member

diemol commented May 7, 2024

It seems BiDi will also match cookies only by name: https://w3c.github.io/webdriver-bidi/#match-cookie

You should raise this issue with https://github.com/w3c/webdriver-bidi and/or https://github.com/w3c/webdriver

@diemol diemol added the G-w3c Requires change to W3C Spec label May 7, 2024
Copy link

github-actions bot commented May 7, 2024

Hi, @dmitryyukhnovets.
This issue has been determined to require a change to the
WebDriver W3C Specification for Selenium to be able to support it.

Please create an issue with the WebDriver project.

Feel free to comment the issues that you raise back in this issue. Thank you.

@github-actions github-actions bot closed this as completed May 7, 2024
@pujagani
Copy link
Contributor

pujagani commented May 7, 2024

Thank you for checking!
I think this is the confusing part and the reason is because the one-liner and detailed description say different things.
However, 'https://w3c.github.io/webdriver-bidi/#get-matching-cookies' bit is mentioned in the details and that is what is implemented by the browsers too. This reminds me to add a test in our implementation as well.

Screenshot 2024-05-07 at 6 40 24 PM

It should be supported by browsers based on the WPT Tests https://github.com/web-platform-tests/wpt/blob/32fdd84c40/webdriver/tests/bidi/storage/delete_cookies/filter.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
G-w3c Requires change to W3C Spec
Projects
None yet
Development

No branches or pull requests

3 participants