New to Telerik Test Studio? Download free 30-day trial

Get/Set Cookies in Code

Here is a working code sample:

Manager.LaunchNewBrowser();

const string url = "http://www.google.com";
{
    var cookie = new Cookie("foo", "bar", "/", url);
    cookie.Expires = DateTime.MaxValue;
    var ok = ActiveBrowser.Cookies.SetCookie(cookie);
}

var c = ActiveBrowser.Cookies.GetCookies("http://www.google.com");
var count = c.Count;

Log.WriteLine(count.ToString());
foreach (Cookie cookie in ActiveBrowser.Cookies.GetCookies("http://www.google.com"))
{
    Log.WriteLine(cookie.Name);
}
Manager.LaunchNewBrowser()

Const  url As String = "http://www.google.com"
If True Then
    Dim cookie = New Cookie("foo", "bar", "/", url)
    cookie.Expires = DateTime.MaxValue
    Dim ok = ActiveBrowser.Cookies.SetCookie(cookie)
End If

Dim c = ActiveBrowser.Cookies.GetCookies("http://www.google.com")
Dim count = c.Count

Log.WriteLine(count.ToString())
For Each cookie As Cookie In ActiveBrowser.Cookies.GetCookies("http://www.google.com")
    Log.WriteLine(cookie.Name)
Next
In this article