Saturday, February 9, 2013

How to work with Cookies in a web site using selenium webdriver

import java.util.Set;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class FindAllCookiesInaWebSite
    public static void main(String[] args)
        WebDriver driver=new FirefoxDriver();
        Set<Cookie> cookies=driver.manage().getCookies();
        //To find the number of cookies used by this site
        System.out.println("Number of cookies in this site "+cookies.size());
        for(Cookie cookie:cookies)
            System.out.println(cookie.getName()+" "+cookie.getValue());
            //This will delete cookie By Name
            //This will delete the cookie
        //This will delete all cookies.


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.