selenium+Java对cookies的操作

public class Demo15 {

public static void main(String[] args) {

	FirefoxDriver driver = new FirefoxDriver();
	
	driver.get("http://www.youdao.com/");
	
	//获取cookies
	Set data = driver.manage().getCookies();
	System.out.println(data);
	//获得cookies个数
	System.out.println(driver.manage().getCookies().size());
	
	//删除所有cookies
	driver.manage().deleteAllCookies();
	//获得cookies个数
	System.out.println(driver.manage().getCookies().size());//此时cookies的个数为0
	
	//设置cookies
	Cookie c1 = new Cookie("JSESSIONID", "A93C195B41FE5252CFB1AFFB381037F2");
	driver.manage().addCookie(c1);
	System.out.println(driver.manage().getCookies().size());//新增了一条,此时cookie个数为1

	driver.close();
	
}

}

你可能感兴趣的:(软件测试)