0

I was wondering if it would be possible to execute the following instructions in a selenium webdriver

Basically what I'm trying to do is the following:

  1. Press Ctrl+Shift+M (⇧⌘M) to toggle device toolbar

  2. Navigate to the Application tab

  3. On the left, expand Local Storage and select https꞉//discord.com

  4. Type Token into the Filter box

So as an example, I attached a screenshot of what it looks like in a selenium browser

enter image description here

Edit: I'm not trying to follow the exact step, but I'm just trying to get the value corresponding the the token key in the image below.

PutsandCalls
  • 997
  • 1
  • 8
  • 11

1 Answers1

0

I doubt that your scenario is possible to execute with your exact steps. There is a reason why CDP and BiDi API was introduced in Selenium 4.

You can use JavaScript to set item in the localstorage:

IJavaScriptExecutor js = (IJavaScriptExecutor)webDriver;
js.ExecuteScript("localStorage.setItem('token','123');");

For Python use: browser.execute_script("localStorage.setItem('token','123');")

For getting the token value: browser.execute_script("localStorage.getItem('token');")

Reference:
Setting LocalStorage with Chrome and Selenium
What does execute_script() in Selenium does
https://www.w3schools.com/jsref/met_storage_getitem.asp

K. B.
  • 3,342
  • 3
  • 19
  • 32
  • Hmm Is it possible to get the value corresponding to the Token key then ? I'm not looking to follow the exact steps but just trying to get the value of the token key. – PutsandCalls May 28 '22 at 07:45
  • Yes, you can localStorage.getItem(keyname) https://www.w3schools.com/jsref/met_storage_getitem.asp I updated my answer – K. B. May 28 '22 at 08:54