thirtyfour icon indicating copy to clipboard operation
thirtyfour copied to clipboard

How to call with cookie ?

Open anhduca4 opened this issue 2 years ago • 6 comments

I want to call to url with cookie . But I saw it not have cookie ? Can you help me for it ?

anhduca4 avatar Aug 06 '22 11:08 anhduca4

Hi, I'm not sure if this is possible with selenium. You can add cookies to the current session (see here) and get the cookies from the browser, but I'm not sure what you mean by "call to url with cookie". Can you provide more info?

stevepryde avatar Aug 06 '22 12:08 stevepryde

My solution is . In my browser after login in my website I will have cookie . Then I want use this cookie no need login again.

anhduca4 avatar Aug 06 '22 13:08 anhduca4

Selenium will automate the browser session in much the same way as a user using the browser. You shouldn't need to do anything special for the cookie to be stored in that browser session. However, each time you start a new browser session via selenium you will need to login again. I don't think there's a way around that. The reason is because both chrome and firefox will create a new profile for that session, which you can think of similar to incognito mode. Once the session ends, all the cookies for that session (and everything else for that profile) will be deleted.

It might be possible to save the cookie details to disk and then add it back into the browser next time (the example I mentioned before has code for adding a cookie to the browser), but I'm not sure about this. Is it definitely using cookies and not local storage? You can access local storage using javascript. You can probably access cookies with JS too, although selenium has built-in cookie support so that shouldn't be necessary.

stevepryde avatar Aug 06 '22 13:08 stevepryde

If you're trying to do multiple tests or things requiring login, probably the best solution is just to automate the login step so that it's automatic and quick.

stevepryde avatar Aug 06 '22 13:08 stevepryde

Thankyou for suport.

anhduca4 avatar Aug 06 '22 14:08 anhduca4

You're welcome. Hope you can get it all working.

stevepryde avatar Aug 06 '22 14:08 stevepryde