Accessing local storage in HTML 5 using Selenium

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')");

Answer №1

To begin with, the value should be returned and then it should be converted to a specific type.

value = (String) js.executeScript("return localStorage.getItem('key')");

Answer №2

To provide an answer, we have an update for you! In 2018, the preferred way to accomplish this with c# is:

browser.WebStorage.LocalStorage.GetItem("item")

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Loop variables undergoing change

I am currently working on a loop that fetches data from an API and then processes it to populate a simple array with the retrieved information. Promise.all(promises.map(obj => API.functionName(obj))).then((response) => { var index = startingDate; ...

When adding another Mesh, an error occurs in three.js stating: "Uncaught TypeError: Cannot read property 'center' of undefined - three.js:6754."

As I delve into coding with JS, I decided to experiment with Three.js. Everything was running smoothly until I included the line scene.add(my_square);. From that point on, my code failed to work and displayed the following error: Uncaught TypeError: Canno ...

Adding middleware to the res.render() function can be extremely helpful when dealing with a large number

Recently, I put together a webpage for local use and it involves many routes. Specifically, I have 31 .ejs files and 3 .html files all neatly stored in the "views" folder. //app.js - using node and express app.get('/page1', function(req, res ...

Issue when passing JSON as props: Unable to access the property 'name' because it is undefined

I have a JSON request that returns a JSON object. I want to pass this data to a component function for display purposes, but I'm encountering the following error: Cannot read property 'name' of undefined I've outlined the issue below ...

Animating toggled classes in React can be achieved by utilizing keyframe animations or

I am looking to implement a simple transition/animation using React and CSS. The concept is to have an image that, when clicked, toggles a new section below with a nice transition effect. This is my React code: const [show, setShow] = useState(false); & ...

Manipulate the Vue slider on an exchange using Python with Selenium

Currently, I am in the process of developing a crypto trading system and do not have access to the exchange API. As a workaround, I decided to experiment with Selenium automation. However, my challenge lies in figuring out how to interact with the vue sli ...

Having difficulty rendering JSON data on an HTML webpage

Currently, I am working on an API App that utilizes the Foursquare API. With the help of my getRequest function, I am able to obtain results in JSON format, which are then displayed in my console.log. However, the challenge lies in parsing the data from J ...

Tips for efficiently transmitting 'text/event-stream' information through express.js

Looking to set up a basic server-sent-event functionality using express.js on the server side: index.js: const app = require('express')(); const index_html = require('path').join(__dirname, 'index.html'); app.get(&ap ...

React and Material UI: troubleshooting problems with layout columns

I'm working on a project with three columns and I want to include a column for removing each row. Is it possible to add a "removing" column on the right? If so, how can I go about doing it? VIEW CODESANDBOX: HERE const CustomTableRow = ({ row, index ...

Learning how to pass multiple rows of data using d3 is essential for effective data

Here is some code that I am working with: var row = 4; var col = 4; var stack = d3.layout.stack(); var layers = stack( d3.range(row).map(function() { return CmcLayer(col); })); function CmcLayer(col) { var a = [1, 2, 3, 4]; return a.map(func ...

Encountering an issue upon pressing the 'calculate' button

Currently, I am delving into express node.js and attempting to execute a straightforward calculator code. However, whenever I click on the button, I do not receive any response, and there are no errors in my code either. I find myself a bit lost in figurin ...

In Chrome, there is a conflict between the screen width when using `position: absolute` and `position: fixed` if there is vertical

I'm in the process of developing a website with a video banner set to fixed positioning in the background, and a div that has absolute positioning covering part of the video on the bottom half. However, I've encountered an issue - when I add this ...

Unable to retrieve JSON data at this time

I am currently attempting to retrieve information from a JSON file using JQuery in my HTML code with the following script: $.getJSON( "en.json", function( data ) { console.log(data.age); }); Unfortunately, it doesn't seem to be working as expe ...

Issue with fullPage.js - Unable to scroll to footer on the last section of the page

I'm currently working with the fullPage.js plugin () and encountering some issues. While sliding through each section, everything functions as expected. However, when I reach the last section and try to scroll down to the footer below it, I encounter ...

Differences between using a getter in Vue.js/Vuex compared to directly accessing state values on the create lifecycle hook

As I utilize the created lifecycle hook within vue.js to fetch data from my store and pass it to a vue component's data, an interesting observation arises. When I employ this.selectedType = store.state.selectedType, the data is successfully retrieved ...

To highlight errors in ASP.NET MVC4 form validation, consider adding a vivid red border around the selectize dropdownlist

I have implemented the selectize framework for my dropdown list in asp.net mvc4 and successfully modified the CSS for all form fields bound to asp.net mvc4's validation engine. However, I am facing an issue with creating a border around the dropdownl ...

ES6 Class Directive for Angular 1.4

I am currently exploring the possibility of incorporating a directive from version 1.4 and adapting it to resemble a 1.5 component. By utilizing bindToController and controllerAs, I aim to integrate the controller within my directive rather than using a se ...

Connection issue in Firefox: NotConnectedException

This is my current setup: java -version openjdk version "1.8.0_40-internal" OpenJDK Runtime Environment (build 1.8.0_40-internal-b27) OpenJDK 64-Bit Server VM (build 25.40-b25, mixed mode) ubuntu 14.04 clj-webdriver I am currently executing the foll ...

How to conceal certain columns in Angular Material when in mobile view

I am currently utilizing an Angular Material table: <div class="table-container"> <table mat-table [dataSource]="dataSource" class="child"> <mat-divider></mat-divider> <ng-container matColumnDef="title" ...

$rootScope undefined in an easy AngularJs Routing Demo

I've been trying to access the name and age using $scope and $rootScope, but I keep getting an error even though I'm pretty sure everything is set up correctly. Can someone please point out where I might be making a mistake? <html> <he ...