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

can not add cookie #130

Open
lidaling opened this issue Jul 23, 2018 · 14 comments
Open

can not add cookie #130

lidaling opened this issue Jul 23, 2018 · 14 comments

Comments

@lidaling
Copy link

After adding a cookie, refresh, I still can not get the added cookie. Here are the codes, anybody has any idea?
Thanks.

err = webDriver.Get("http://localhost:9080")
	if err != nil {
		panic(fmt.Sprintf("Failed to load page: %s\n", err))
	}
	webDriver.AddCookie(&selenium.Cookie{
		Name:  "eds_aa",
		Value: "the check value",
	})
	webDriver.Refresh()

	cookies, _ := webDriver.GetCookies()
	for _, v := range cookies {
		log.Println("cookie is "+v.Name)
	}
@minusnine
Copy link
Collaborator

What are the values of the errors that you are discarding from AddCookie and GetCookies?

@lidaling
Copy link
Author

@minusnine
No errors,just print the default cookies.No cookie named eds_aa print

@small-lei
Copy link

webDriver.AddCookie(&selenium.Cookie{
Name: "eds_aa",
Value: "the check value",
})

add cookie no return cookie

@small-lei
Copy link

??????

@small-lei
Copy link

�I have the same problem, After adding a cookie, refresh, I still can not get the added cookie. Here are the codes, anybody has any idea?
Thanks.

@mybee
Copy link

mybee commented Jul 31, 2019

I have the same problem.....

@minusnine
Copy link
Collaborator

minusnine commented Jul 31, 2019

This test currently passes:

func testAddCookie(t *testing.T, c config) {

Can you please provide debug logs from Geckodriver or ChromeDriver? See here for an example of how to do that:

if testing.Verbose() {

Or better:

  1. Send a pull request which changes the testAddCookie function in a way that demonstrates the failure.
  2. Run go test -test.run=.*/AddCookie -test.v and attach the output.

@ZhangYiX
Copy link

Have you solved this problem?

@nguyening
Copy link

My issue was that the cookie was expiring immediately, I added an epoch timestamp in the future to get it to stick

@andy80038
Copy link

andy80038 commented Nov 22, 2019

oh.. I have the same problem.....
pick me :
just ues //Expiry: math.MaxUint32
wd.AddCookie(&selenium.Cookie{
Name: cook.Name,
Value: cook.Value,
Expiry: math.MaxUint32, //***
})

@Amberlyd
Copy link

thanks to @minusnine 's advice , I solve this issue by strictly follow demo and rewrite the code
like

session := &selenium.Cookie{
	Name: "session",
	Value: "32904a4ac31a5a34984070740553a2ca",
	Expiry: math.MaxUint32,
}
session.Domain = "10.250.129.10"
session.Path = "/"
err = wd.AddCookie(session)````

and it works !!!

@ultraxia
Copy link

ultraxia commented Dec 12, 2019

I have the same problem ... i try to set Expiry to math.MaxUint32, but it still doesn't work : (

for _, v := range cookies {
	session := &selenium.Cookie{
		Name:   v.Name,
		Value:  v.Value,
		Expiry: math.MaxUint32,
	}
	session.Domain = v.Domain
	session.Path = "/"
	err = webDriver.AddCookie(session)
}

Is there anyone can help me?

@ultraxia
Copy link

Oh...I have solved this problem,if anyone have set Expiry to math.MaxUint32 and the code is still doesn't work, try the following ideas.

You should load the webpage first so that selenium knows which website the cookie belongs to, although the behavior of loading the webpage is not useful to us.

Thanks for @lidaling 's advice.

	webDriver.Get(config["target_url"])
	
	for _, v := range cookies {
		session := &selenium.Cookie{
			Name:   v.Name,
			Value:  v.Value,
			Expiry: math.MaxUint32,
		}
		session.Domain = v.Domain
		session.Path = "/"
		session.Secure = false

		err = webDriver.AddCookie(session)

	}
	webDriver.Refresh()

@yuseferi
Copy link

the following code is working for me

cookies, _ := wd.GetCookies()

for _, v := range cookies {
	session := &selenium.Cookie{
		Name:   v.Name,
		Value:  v.Value,
		Expiry: math.MaxUint32,
	}
	session.Domain = v.Domain
	session.Path = "/"
	session.Secure = false

	err = wd.AddCookie(session)

}
wd.Refresh()

qwenode added a commit to qwenode/selenium that referenced this issue Sep 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants