Skip to main content

spydr

Selenium Python WebDriver Wrapper - Commonly used WebDriver functionality in a package.

spydr WebDriver - Spydr documentation

spydr WebElement - SpydrElement documentation

Install

pip install spydr

Supported locator

Spydr WebDriver supports locator using the following how=what strategies to locate elements:

  • css=.btn
  • class=btn-primary
  • id=frame1
  • link_text=Click here
  • name=j_username
  • partial_link_text=Go to
  • tag_name=span
  • text=Save As Draft
  • xpath=//span/a
  • yml=today_page.dashboard.search_field

If how is not specified, locator starting with / or ( will be parsed as xpath, while ., [ and # are treated as css.

locator also supports css pseudo selector :eq(), like using .tab:eq(2) to locate 3rd element of .tab.

Using Sypdr WebDriver

# Basic Example 1:
# - Google search 'webdriver'
from spydr.webdriver import Spydr

s = Spydr()
s.maximize_window()
s.open('https://www.google.com/')
s.send_keys('name=q', 'webdriver', s.keys.ENTER)
s.save_screenshot('sample-1')
s.quit()
# Basic Example 2:
# - Firefox driver, in headless mode, with 1920x1080 resolution
# - Switch frame and window
from spydr.webdriver import Spydr

s = Spydr(browser='firefox', headless=True, log_level='INFO', window_size='1920,1080')
s.info('JSFiddle: Test "Open New Tab/Window"')
s.maximize_window()
s.open('https://jsfiddle.net/s7gcx1du/')
s.switch_to_frame('name=result')
s.click('link_text=New Window', switch_to_new_target=True)
s.save_screenshot(s.timestamp(prefix='sample-'))
s.quit()
# Handle Basic/Digest HTTP AUTH using Chrome
from spydr.webdriver import Spydr

s = Spydr(auth_username='guest', auth_password='guest')
s.open('https://jigsaw.w3.org/HTTP/Basic/')
s.save_screenshot('basic')
s.open('https://jigsaw.w3.org/HTTP/Digest/')
s.save_screenshot('digest')
s.quit()
# Handle Basic/Digest HTTP AUTH using non-Chrome
from spydr.webdriver import Spydr

s = Spydr(browser='firefox', auth_username='guest', auth_password='guest')
s.open_with_auth('https://jigsaw.w3.org/HTTP/Basic/')
s.save_screenshot('basic')
s.open_with_auth('https://jigsaw.w3.org/HTTP/Digest/')
s.save_screenshot('digest')
s.quit()

Using YML: Dot Notation

# conf.yml
env:
  url: 'https://dev.company.com/today'

today_page:
  dashboard:
    search_field: '#dashboard-search'
    search_string: 'name is {name}'
from spydr.webdriver import Spydr

s = Spydr(yml='conf.yml')

url = s.t('env.url')
search_string = s.t('today_page.dashboard.search_string', name='spydr')

s.open(url)
s.send_keys('yml=today_page.dashboard.search_field', search_string)  # using yml as locator

Using INI: JSON serialization

; conf.ini
[Spydr]
url = "https://www.google.com"
query = "webdriver"
from spydr.webdriver import Spydr

s = Spydr(ini='conf.ini')

url = s.get_ini_key('url')
query = s.get_ini_key('query')

s.open(url)
s.send_keys('name=q', query, s.keys.ENTER)

first_result = s.text('.r > a h3:eq(0)')  # Get first search result
s.set_ini_key('first_result', first_result)  # add first_result to the INI file
all_results = s.texts('.r > a h3') # Get all results
s.set_ini_key('all_results', all_results)  # add all results to the INI file
s.save_ini()  # Save the INI file

s.quit()

SpydrElement (WebElement with Spydr functionality)

from spydr.webdriver import Spydr

s = Spydr()

# ...

table = s.find_element('#table')

td = table.find_element('css=td[data-id="12345"]')

if td.parent_element.last_child.text == 'complete':
    td.next_element.find_element('.comment').send_keys('Comment here', blur=True)
else:
    td.parent_element.first_child.find_element('css=a.update').click()

Development Environment

cd spydr
pip install -e .
pip install autopep8
pip install pylint
pip install twine
pip install wheel
pip install sphinx
pip install sphinxcontrib-napoleon

Build Docs

cd spydr
sphinx/make html

Upload Package

cd spydr
python -B setup.py bdist_wheel
twine upload dist/*

Project Home

https://pypi.org/project/spydr/

Metadata

Release files for spydr 0.6.1

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

Built distribution (wheel)

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

Release files / spydr-0.6.1-py3-none-any.whl

Download URL spydr-0.6.1-py3-none-any.whl
Size 33.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e734637f97595ee635ef602f558b01c9c03449e5c01b0705440720d3eb77dbea
BLAKE2b-256 checksum
How to use checksums
a423e40e385f558e999801ba73ecb6b6fb44bc19c059b7e19e7c3a4eed91fc08
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.9.1

Security for spydr 0.6.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.6.1 This release

1 release file No provenance

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