selenium+java 获得 cookie

public class CookieDemo {

    public static void main(String[] args){
        
        //驱动配置
        System.setProperty("webdriver.chrome.driver","D:\\driver\\chromedriver.exe"); 
        WebDriver driver = new ChromeDriver();
        driver.get("http://www.baidu.com");
        
        Cookie c1 = new Cookie("name","name");
        Cookie c2 = new Cookie("value","value");
        driver.manage().addCookie(c1);
        driver.manage().addCookie(c2);

        //获得 cookie
        Set coo =driver.manage().getCookies();
        System.out.println(coo);

        //删除所有cookie
        //driver.manage().deleteAllCookies();

        driver.quit();



    }
}

 

你可能感兴趣的:(基础篇,持续更新,..)