Re: Retrieve Cookies from multiple domains

142 views
Skip to first unread message
Message has been deleted

David

unread,
Jan 25, 2018, 2:31:20 PM1/25/18
to Selenium Users
AFAIK, there is no direct way to do it via Selenium or pure javascript.

Your best option if you know the list of domains is to navigate to each domain then call get cookies. And unless you can pull from browser history (via javascript, etc.) to get the list of domains that have been visited, there's no way to go through all visited domains for cookies.

On Wednesday, January 24, 2018 at 8:14:37 PM UTC-8, Sanju wrote:
Hi all,
Could you please let me know how to access cookies from multiple domains of a Chrome Browser?

Note: driver.manage().getCookies() - this one gives cookies for the current domain only.

Thank You!

Java Selenium35

unread,
Jan 25, 2018, 6:57:42 PM1/25/18
to seleniu...@googlegroups.com
Thank you for the response David. Can you pls suggest how do I navigate to a particular domain? In my case the domain name is always the same.

--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/O4nXra2kleM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/e1853a40-5b9a-494d-98e9-7bd34d1ad7ac%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

David

unread,
Jan 26, 2018, 3:04:10 PM1/26/18
to Selenium Users
something like this should do:

driver.get("domain URL of interest here"); //or equivalent command to navigate to a given URL

run that before calling get cookies, and repeat for every domain you want to get cookies for. If cookies exist for the domain it will pull those cookies, if domain has never been visited, it will just fetch you the newly created cookies upon visiting the domain (if any cookies are created at all). Doesn't matter for exact URL used, it just has to be for domain of interest (the FQDN), the resource path at the end of the URL if not using a base domain URL doesn't matter.

this of course means navigating away from current domain (that you will have to navigate back to). if that is a concern, open a new window and go to new domain + fetch cookies from there and close it out when done - you can open/create new window/tab with javascript executor, if Selenium doesn't provide an API for it.

On Thursday, January 25, 2018 at 3:57:42 PM UTC-8, Sanju wrote:
Thank you for the response David. Can you pls suggest how do I navigate to a particular domain? In my case the domain name is always the same.
On Jan 25, 2018 2:31 PM, "David" <mang...@gmail.com> wrote:
AFAIK, there is no direct way to do it via Selenium or pure javascript.

Your best option if you know the list of domains is to navigate to each domain then call get cookies. And unless you can pull from browser history (via javascript, etc.) to get the list of domains that have been visited, there's no way to go through all visited domains for cookies.


On Wednesday, January 24, 2018 at 8:14:37 PM UTC-8, Sanju wrote:
Hi all,
Could you please let me know how to access cookies from multiple domains of a Chrome Browser?

Note: driver.manage().getCookies() - this one gives cookies for the current domain only.

Thank You!

--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/O4nXra2kleM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages