3

i want to retrieve all cookies names and domains from an URl using selenium webdriver xx.21 with java,

i am using this below code:

driver.navigate().to("http://www.nextag.com");
Set<Cookie> cookies = driver.manage().getCookies();
Iterator<Cookie> itr = cookies.iterator();

    while (itr.hasNext()){
    Cookie c = itr.next();
    System.out.println("Cookie Name: " + c.getName() + " --- " + "Cookie Domain: " + c.getDomain() + " --- " + "Cookie Value: " + c.getValue());
    }

From the above code i am getting only some but when i check manually there are some more cookies has to be dropped by advertisements, like (scorecardresearch.com) cookies which is expected, How to get all those by selenium code? Any answer would be really helpful. Thank you

vamsi chandra
  • 61
  • 2
  • 3
  • driver.manage().getCookies() will only return cookies associated with the currently loaded domain. I don't believe there is any natively supported method in selenium to delete or retrieve all cookies. Using javascript is going to be unsuccessful as well. Security restrictions aren't going to allow you to pull cookies from other sites. – AndyPerfect May 11 '12 at 17:42
  • 1
    hi, Thank q for reply,-But from the same domain only other cookies are coming!! – vamsi chandra May 12 '12 at 18:38
  • 1
    Is this still an issue? Because I've got a solution if you're using the Firefox WebDriver... (It's been awhile, so maybe you've found a workaround?) – jcovert Oct 26 '12 at 20:24
  • @jcovert Can you share your solution? I would like to access the 3rd Party cookies, and have not seen a solution yet. – mondo Jul 22 '13 at 16:34

1 Answers1

2

There is a workaround for this using a Mozilla firefox add-on which will save all cookies in XML format under current profile directory. This add-on will save cookies from all domains and can be accessed using webdriver.

For more details on implementation using C#, refer to following blog: http://automationoverflow.blogspot.in/2013/07/getting-cookies-from-all-domains.html

Vishnu
  • 319
  • 2
  • 4