1. 程式人生 > >selenium+java 獲得 cookie

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<Cookie> coo =driver.manage().getCookies();
        System.out.println(coo);

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

        driver.quit();



    }
}