How to access IndexedDB by Selenium (python)

334 views
Skip to first unread message

Bruno Walter

unread,
Jul 4, 2023, 11:15:09 PM7/4/23
to Selenium Users
Hello!

Please, could someone help me with a simple issue of implementing Selenium with IndexedDB? I already consulted https://pypi.org/project/seletools/ , but it wasn't enough (including "logging" by "desired_capabilities" is deprecated).

Basically the code I wrote is:

import time
from selenium.webdriver.common.by import By
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service 
from seletools.indexeddb import IndexedDB

# # Configurações do Driver Options
ops = webdriver.ChromeOptions()

prefs = {"browser": "ALL",
'performance' : 'ALL',
'enableNetwork' : True,
'enablePage' : True,
}
ops.add_experimental_option('prefs', prefs)
servico = Service(ChromeDriverManager().install())
browser = webdriver.Chrome(service=servico, options=ops)


idb = IndexedDB(browser, "dbname", 1) # webdriver instance, db name, db version
value = idb.get_value("[thekey", "tablename") # table name, key in table

it happens that Selenium does not find the IndexedDB database (even when I manually access it via F12 in the window opened by Selenium, it is not present).

Any suggestions where I might be wrong? Any help is welcome (I'm still taking my first steps in programming).

Thanks,

Bruno W.

Dmitrii Bormotov

unread,
May 13, 2024, 12:24:07 AMMay 13
to Selenium Users
You're setting logging preference wrong.
I updated README section with examples for both Selenium 3 & 4 - just follow a setup for whatever version you use.

I'm duplicating these examples here as well 👇

#### Setup - Selenium 3
```
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

dc = DesiredCapabilities.CHROME
dc["goog:loggingPrefs"] = {"browser": "ALL"}
driver = webdriver.Chrome(desired_capabilities=dc)
```

#### Setup - Selenium 4
```
from selenium import webdriver

options = webdriver.ChromeOptions()
options.set_capability("goog:loggingPrefs", {"browser": "ALL"})
```
Reply all
Reply to author
Forward
0 new messages