Skip to main content

Page object model made easy.

Project description

Page object model made easy.

  • Free software: BSD 2-Clause License


pip install selenium-elements


To use the project:

from contextlib import contextmanager

import pytest
from selenium import webdriver
from import By
from import staleness_of
from import WebDriverWait

from selenium_elements.conditions import clickable
from selenium_elements.elements import PageElement, PageElements, RegionElements
from import Page, Region
from selenium_elements.validators import title_matches, url_contains

def wait_for_page_load(driver, timeout=30):
    old_page = driver.find_element_by_tag_name("html")
    WebDriverWait(driver, timeout).until(staleness_of(old_page))

class Show(Page):
    path = "/show/{show_slug}/"
    validators = [title_matches("^[a-zA-Z]+ | PBS$"), url_contains("")]

    official_website_btn = PageElement(By.CLASS_NAME, "btn--visit", condition=clickable)

    def official_website_link(self):
        return self.official_website_btn.get_attribute("href")

class PromoShowRegion(Region):
    title_element = PageElement(By.CLASS_NAME, "carousel--show-strip__image-link")

    def open(self):
        with wait_for_page_load(self.driver):
        return Show(driver=self.driver, base_url=self.base_url, visit=False)

    def title(self):
        return self.title_element.get_attribute("data-gtm-label")

class Home(Page):
    path = "/"
    load_timeout = 30
    validators = [
        title_matches("^PBS: Public Broadcasting Service$"),

    promo_show_elements = PageElements(
        By.CLASS_NAME, "show-promo", find_on_page_load=True
    promo_shows = RegionElements(
        region_class=PromoShowRegion, root_element=promo_show_elements

def driver():
    driver = webdriver.Chrome()
    yield driver

def test_foo(driver):
    home = Home(driver=driver, base_url="")
    for show in home.promo_shows:
    show = home.promo_shows[0].open()
    assert True

Project details

Download files

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

Files for selenium-elements, version 0.0.2
Filename, size File type Python version Upload date Hashes
Filename, size selenium_elements-0.0.2-py2.py3-none-any.whl (8.5 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size selenium-elements-0.0.2.tar.gz (10.7 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page