I have been working with Selenium web driver in C# and I encountered a weird issue. When I use a JavaScript method to write to local storage, it works perfectly fine (I can see the values when inspecting the HTML page), but when I try to read from the local storage, it always returns null. Any help on this would be greatly appreciated.
Writing (works):
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
js.ExecuteScript("localStorage.setItem('key', 'value');");
Reading (returns Null):
Object Value = js.ExecuteScript("localStorage.getItem('key')");