使用 Selenium WebDriver Java 绑定清除浏览器 Cookie
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35403614/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Clear browser Cookies with Selenium WebDriver Java bindings
提问by Tom J Muthirenthi
Does anyone know if it's possible to Clear Browser Cookies for WebDriver before starting the automation? (Note: Not Selenium RC)
有谁知道在开始自动化之前是否可以清除 WebDriver 的浏览器 Cookie?(注意:不是 Selenium RC)
采纳答案by Guy
Yes, it's possible
是的,有可能
driver.manage().deleteAllCookies();
Call it right after you are creating the new WebDriver instance.
创建新的 WebDriver 实例后立即调用它。
WebDriver driver = new ChromeDriver();
driver.manage().deleteAllCookies();
You can also delete the cookies one by one
您也可以一一删除cookies
Set<Cookie> allCookies = driver.manage().getCookies();
for (Cookie cookie : allCookies) {
driver.manage().deleteCookieNamed(cookie.getName());
}
回答by Jyothishwar Deo
Does this work for you?
这对你有用吗?
driver.manage().deleteAllCookies();
回答by Monsignor
ChromeDriver
provides a way to clear cookies of allwebsites/domains:
ChromeDriver
提供了一种清除所有网站/域的cookie 的方法:
driver.ExecuteChromeCommand("Storage.clearCookies", new Dictionary<string, object>())