Third party cookie access

1,391 views
Skip to first unread message

Stephen Day

unread,
Apr 20, 2011, 4:27:55 PM4/20/11
to Selenium Users
I have a need to check the status of requests fired off to third
parties through various methods (ajax requests, img loads, etc.).
Generally, I need to do this by confirming that the proper cookie was
dropped. During my evaluation of the Selenium platform, I have been
using the java webdriver api:

WebDriver driver = new FirefoxDriver();
String someURL = ...;
try {

driver.get(someURL);

Set<Cookie> cookies = driver.manage().getCookies();
System.out.println(cookies);

} finally {
driver.quit();
}

When I set "someURL" to a test page that includes third party cookies
(set via ajax, imgs or scripts), they are not returned by the
getCookies function. I do understand the security model to limit
access to cookies in a standard browsing scenario, but in a test
scenario, it seems that one should have access to these.

Is there some way to access the browser cookie store from Selenium/
WebDriver?

I am using the jars available in selenium-java-2.0b3.

Thank you for your time,
Stephen

AJ

unread,
Apr 21, 2011, 8:01:10 AM4/21/11
to Selenium Users
Selenium has a method to retrieve specific cookie by its name
selenium.getCookieByName("CookieName");

Not sure about webDriver though...

Stephen Day

unread,
Apr 22, 2011, 1:44:54 PM4/22/11
to Selenium Users
WebDriver definitely has this method available, as well, under
WebDriver.Options[1]. However, this suffers from the same issue.
Cookies that are set for domains other than for the current page are
not available.

It sounds like this is unsupported functionality, but I wanted to
clarify whether this was a conscious decision or a "side-effect" of
the browsers security model.

[1] http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/WebDriver.Options.html

On Apr 21, 5:01 am, AJ <anand...@gmail.com> wrote:
> Selenium has a method to retrieve specificcookieby its name
> selenium.getCookieByName("CookieName");
>
> Not sure about webDriver though...
>
> On Apr 21, 1:27 am, Stephen Day <stevv...@gmail.com> wrote:
>
>
>
>
>
>
>
> > I have a need to check the status of requests fired off tothird
> > parties through various methods (ajax requests, img loads, etc.).
> > Generally, I need to do this by confirming that the propercookiewas
> > dropped. During my evaluation of the Selenium platform, I have been
> > using the java webdriver api:
>
> >         WebDriver driver = new FirefoxDriver();
> >         String someURL = ...;
> >         try {
>
> >             driver.get(someURL);
>
> >             Set<Cookie> cookies = driver.manage().getCookies();
> >             System.out.println(cookies);
>
> >         } finally {
> >             driver.quit();
> >         }
>
> > When I set "someURL" to a test page that includesthirdpartycookies
> > (set via ajax, imgs or scripts), they are not returned by the
> > getCookies function. I do understand the security model to limit
> > access to cookies in a standard browsing scenario, but in a test
> > scenario, it seems that one should have access to these.
>
> > Is there some way to access the browsercookiestore from Selenium/

Luke Inman-Semerau

unread,
Apr 22, 2011, 3:16:18 PM4/22/11
to seleniu...@googlegroups.com
I think your assumptions are correct. 

Possible work around for you is to open up a page in the domains of the third parties and verify the cookies there (probably to some innocuous page that doesn't set cookies, like a 404 page or an image or css, as to not affect the values). Hopefully this is just one test case and you don't have to do this in the middle of all your other tests.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.


vishnu

unread,
Jul 30, 2013, 12:06:16 PM7/30/13
to seleniu...@googlegroups.com
Fortunately, there is a feasible solution to this problem, though works only for Firefox.


Thanks,
Vishnu
Reply all
Reply to author
Forward
0 new messages