[英]How to clear session storage using selenium c#?
I have already tried this, but it shows error while debugging我已经试过了,但是调试时显示错误
IWebStorage webStorage = (IWebStorage)driver;
webStorage.LocalStorage.Clear();
webStorage.SessionStorage.Clear();
error: "Unable to cast object of type 'OpenQA.Selenium.Chrome.ChromeDriver' to type 'OpenQA.Selenium.Html5.IWebStorage" error: "Unable to cast object of type 'OpenQA.Selenium.Chrome.ChromeDriver' to type 'OpenQA.Selenium.Html5.IWebStorage"
You can clear local storage and session storage with javaScript executor.您可以使用 javaScript 执行器清除本地存储和 session 存储。
(driver as IJavaScriptExecutor).ExecuteScript("sessionStorage.clear();");
(driver as IJavaScriptExecutor).ExecuteScript("localStorage.clear();");
Just keep in mind that session and local storage are stored specific to a page so you have to load the url of the page you want to clear before executing the script.请记住,session 和本地存储是特定于页面存储的,因此您必须在执行脚本之前加载要清除的页面的 url。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.