Selenium Webdriver wrapper with Selenium IDE-like functionality
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=text
name=j_username
partial_link_text=text
tag_name=span
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/Winodw"')
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 wrapped with Spydr specfic 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 sphinx
pip install sphinxcontrib-napoleon
Build Docs
cd spydr
sphinx/make html
Upload Package
cd spydr
python setup.py bdist_wheel
twine upload dist/*
Project Home
Project details
Release history Release notifications | RSS feed
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.3.1-py3-none-any.whl
(24.8 kB
view hashes)