I am using selenium web driver in c#. when i write to local storage with JavaScript method it works fine ( i can see the values in the html page with inspect ), but if i try to read from local storage what i just wrote it returns Null. Thanks for any help .
Writing (works):
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
js.ExecuteScript("localStorage.setItem('key','value');");
Reading (returns Null ):
Object Value= js.ExecuteScript("localStorage.getItem('key')");
localStorage as a type of web storage is an HTML5 specification. It is supported by major browsers including IE8. To be sure the browser supports localStorage , you can check using the following snippet: if (typeof(Storage) !==
First of all, you should return the value, secondly you should cast the return value to a known type.
value = (String) js.executeScript("return localStorage.getItem('key')");
Update to the question, in 2018 with c# you would do:
browser.WebStorage.LocalStorage.GetItem("item")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With