简体   繁体   中英

Clear browser Cookies with Selenium WebDriver Java bindings

Does anyone know if it's possible to Clear Browser Cookies for WebDriver before starting the automation? (Note: Not Selenium RC)

Yes, it's possible

driver.manage().deleteAllCookies();

Call it right after you are creating the new WebDriver instance.

WebDriver driver = new ChromeDriver();
driver.manage().deleteAllCookies();

You can also delete the cookies one by one

Set<Cookie> allCookies = driver.manage().getCookies();
for (Cookie cookie : allCookies) {
    driver.manage().deleteCookieNamed(cookie.getName());
}

这对你有用吗?

driver.manage().deleteAllCookies();

ChromeDriver提供了一种清除所有网站/域的 cookie 的方法:

driver.ExecuteChromeCommand("Storage.clearCookies", new Dictionary<string, object>())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM