Skip to main content

Selenium Tools

PyPI - Downloads Quality Control

About package

Current package is called Selenium Tools for a reason - it contains useful helpers that are not included into Selenium natively.

Contributions are very welcome!

Installation

pip install seletools

Drag & Drop

There is a known drag & drop bug that reproduces in frameworks that use webdriver to send commands to browser. This bug is a webdriver's issue, and it's unknown when it's going to be fixed (or if it's going to be fixed at all). Current solution uses JavaScript code to simulate drag & drop action on web page. It works in most of the cases when it doesn't work in Selenium.

You may find bug description and current workaround here.

Thanks to druska for his native js drag and drop helper.

from seletools.actions import drag_and_drop

driver = webdriver.Chrome()
source = driver.find_element(By.CSS_SELECTOR, "...")
target = driver.find_element(By.CSS_SELECTOR, "...")
drag_and_drop(driver, source, target)

Scroll

This one helps to scroll vertically to any element on page, even if it's covered by some other element (like navbar or footer). If there's such obstacle - simply add that covering element into scrolling function as element2.

from seletools.actions import scroll_to_top, scroll_to_bottom

driver = webdriver.Chrome()
element1 = driver.find_element(By.CSS_SELECTOR, "...")
element2 = driver.find_element(By.CSS_SELECTOR, "...")  #optional, used only if you have obastacle (like navbar on footer) on top of the element that you need to scroll to

scroll_to_top(driver, element1, element2)
# OR
scroll_to_top(driver, element1)

scroll_to_bottom(driver, element1, element2)
# OR
scroll_to_bottom(driver, element1)

Getting webdriver's wait values

Selenium 4 already supports that feature, but versions prior 4 (3.141.0-) doesn't.

# get implicit wait value only
from seletools.waits import get_implicit_wait

implicit_wait = get_implicit_wait(driver)

# OR get all waits (non only implicit one)
from seletools.waits import Wait

waits = Waits(driver)
implicit_wait = waits.implicit
page_load = waits.page_load 
scripts = waits.scripts

Interaction with IndexedDB

It's possible to interact with IndexedDB database in browser via JavaScript. This interface helps get/update/insert data in existing databases and tables.

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"})

Example:

from seletools.indexeddb import IndexedDB

idb = IndexedDB(driver, "mydb", 3)  # webdriver instance, db name, db version
# GET value
value = idb.get_value("keyvaluepairs", "foo")  # table name, key in table
# PUT value (change existing)
idb.put_value("keyvaluepairs", "foo", "win")  # table name, key, new value
# ADD value
idb.add_value("keyvaluepairs", "war", "pain")  # table name, new key, new value
# REMOVE item
idb.remove_item("keyvaluepairs", "foo")  # table name, key in table

Interaction with Local Storage

Selenium doesn't support any Local Storage interactions natively, so usually actions like get/set were done with simple JavaScript snippets.

from seletools import localstorage

# GET value
value = localstorage.get_value(driver, "foo")  # webdriver instance, key in Local Storage
# SET value
localstorage.get_value(driver, "foo")  # webdriver instance, key in Local Storage, new value
# REMOVE item
localstorage.remove_item(driver, "foo")  # webdriver instance, key in Local Storage

Notes

HTML5 Drag & Drop action worked with CSS selectors only a while ago. Now it also supports XPath selectors.

Metadata

Release files for seletools 1.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for seletools 1.5.0
File Size Uploaded
seletools-1.5.0.tar.gz 6.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for seletools 1.5.0
File Interpreter ABI Platform
seletools-1.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.2 kB

Release files / seletools-1.5.0.tar.gz

Download URL seletools-1.5.0.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
6fb57cff898f245148b0db1faf310630f4a9caa33f1f855bdc161c1ad845db67
BLAKE2b-256 checksum
How to use checksums
ac2fe3f169dc90af7a9488b38d56f844a29a08c20510b785cc4fbaa121ebf0d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.3

Release files / seletools-1.5.0-py3-none-any.whl

Download URL seletools-1.5.0-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
afbea99d1943b721e5f49e6c7fd776ce5622c83fd6779893969b1b5da84608fb
BLAKE2b-256 checksum
How to use checksums
d5bd5ced855902e94c2f0a1bbff90bde8836f5eeb2bb1004d864fc639c582e17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

1.5.0 This release

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.5

2 release files

1.0.4

1 release file

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page