Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving 3rd party and All Cookies using Selenium Webdriver Java

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

like image 829
vamsi chandra Avatar asked May 22 '26 22:05

vamsi chandra


1 Answers

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

like image 175
Vishnu Avatar answered May 25 '26 12:05

Vishnu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!