Skip to main content

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

Project description

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/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

spydr-0.6.1-py3-none-any.whl (33.5 kB view details)

Uploaded Python 3

File details

Details for the file spydr-0.6.1-py3-none-any.whl.

File metadata

  • Download URL: spydr-0.6.1-py3-none-any.whl
  • Upload date:
  • Size: 33.5 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for spydr-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e734637f97595ee635ef602f558b01c9c03449e5c01b0705440720d3eb77dbea
MD5 8d3683d3f5eb4b8e1a62baf7cdfff79d
BLAKE2b-256 a423e40e385f558e999801ba73ecb6b6fb44bc19c059b7e19e7c3a4eed91fc08

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page