WebDriver get Session Storage variables

1,505 views
Skip to first unread message

Julius Hamilton

unread,
Oct 28, 2021, 9:02:23 AM10/28/21
to Selenium Users
Hey,

I have a command which I am pretty confident can print the Session Storage variables from the driver, but I am pretty sure the issue is that the Selenium Web Driver isn't getting all the local or session storage variables that my normal browser does, so the variables aren't there.

Could anyone please let me know how to make sure the WebDriver gets all the session storage variables?

Thanks very much,
Julius

David

unread,
Oct 28, 2021, 2:48:22 PM10/28/21
to Selenium Users
What do you find missing?  And what command are you using with the driver that you are confident will return all the session storage variables?

Julius Hamilton

unread,
Oct 28, 2021, 6:01:58 PM10/28/21
to seleniu...@googlegroups.com
If I load a number of web pages in my browser I see a number local and/or session storage variables in the Developer Tools.

But when I call this command on one of their keys:

driver.execute_script(“return sessionStorage.getItem(‘#{key}’)”)

it doesn’t return anything.

But if I do

driver.execute_script(“return localStorage.key(0)”) it successfully returns the key of one of the variables.

If I do:

driver.execute_script(“return localStorage.key(1)”) it returns nothing, even though I can see in my browser there are more local storage variables.

So it seems strongly that not all the storage variables are there, in the webdriver.

Do you think so?
Can you provide an example of retrieving all session storage variables, and not just some?

Thanks very much,
Julius


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/85c94afc-4e7e-428d-81ac-99ebd83c7609n%40googlegroups.com.

Julius Hamilton

unread,
Oct 28, 2021, 6:20:06 PM10/28/21
to seleniu...@googlegroups.com
It might be because it’s headless.

I’ll try it non-headless.

But how could I get those variables in a headless browser?

Julius Hamilton

unread,
Oct 29, 2021, 7:22:54 AM10/29/21
to seleniu...@googlegroups.com
Just an update on this:


The simplest formulation of the problem is expressed in this Stack Overflow post:




www.google.com has session storage variables.

But driver.execute_script(“return sessionStorage.length”) returns 0.

Why?

 Can anyone provide a command that returns those session storage variables in Selenium?

Thanks very much.
Reply all
Reply to author
Forward
0 new messages