简体   繁体   English

使用Selenium Webdriver Java检索第三方和所有Cookie

[英]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, 我想使用selenium webdriver xx.21和java从URl中检索所有cookie名称和域名,

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? 从上面的代码我只得到一些,但当我手动检查时,还有一些饼干必须通过广告删除,如(scorecardresearch.com)预期的cookie,如何通过selenium代码获取所有这些? Any answer would be really helpful. 任何答案都会非常有用。 Thank you 谢谢

There is a workaround for this using a Mozilla firefox add-on which will save all cookies in XML format under current profile directory. 有一个使用Mozilla firefox 附加组件的解决方法,它将在当前配置文件目录下以XML格式保存所有cookie。 This add-on will save cookies from all domains and can be accessed using webdriver. 此附加组件将保存所有域中的cookie,并可使用webdriver访问。

For more details on implementation using C#, refer to following blog: http://automationoverflow.blogspot.in/2013/07/getting-cookies-from-all-domains.html 有关使用C#实现的更多详细信息,请参阅以下博客: http//automationoverflow.blogspot.in/2013/07/getting-cookies-from-all-domains.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM