Skip to main content

A small library for simplifying a table object in selenium

Project description


Build Status codecov PyPi


A small library for simplifying a table object in selenium


If you have pip on your system, you can simply install or upgrade the Python bindings:

pip install selenium-datatable

Alternately, you can download the source code and run:

python install


A table object class implementation:

# -- FILE:
from import By
from selenium_datatable import DataTable, Column

class UsersTable(DataTable):
    rows_locator = (By.CSS_SELECTOR, "tbody > tr")
    headers_locator = (By.CSS_SELECTOR, "thead > tr > th")
    # columns
    last_name = Column(By.CSS_SELECTOR, "tr:nth-of-type({row}) td:nth-of-type(1)")
    first_name = Column(By.CSS_SELECTOR, "tr:nth-of-type({row}) td:nth-of-type(2)")
    email = Column(By.CSS_SELECTOR, "tr:nth-of-type({row}) td:nth-of-type(3)")
    due = Column(By.CSS_SELECTOR, "tr:nth-of-type({row}) td:nth-of-type(4)")
    web_site = Column(By.CSS_SELECTOR, "tr:nth-of-type({row}) td:nth-of-type(5)")
    delete_button = Column(By.CSS_SELECTOR, "tr:nth-of-type({row}) td:nth-of-type(6) a[href='#delete']")
    edit_button = Column(By.CSS_SELECTOR, "tr:nth-of-type({row}) td:nth-of-type(6) a[href='#edit']")

A page object class implementation:

# -- FILE:
from table import UsersTable

class HomePage:    
    items_list = UsersTable("id", "table1")

    def __init__(self, driver, url='http://localhost/tables'):
        self.driver = driver
        self.url = url           

    def open(self):


# -- FILE:
import unittest
from selenium.webdriver import Chrome
from home_page import HomePage

class TestTable(unittest.TestCase):

    def setUp(self):
        self.driver = Chrome() = HomePage(self.driver)

    def test_get_item_from_first_row(self):        
        item =        
        self.assertEqual(item.first_name.text, 'John')
        self.assertEqual(item.last_name.text, 'Smith')
        self.assertEqual(, '')

    def test_get_item_by_property(self):
        item ='Doe', first_name='Jason')    
        assert item.first_name.text == 'Jason'
        assert item.last_name.text == 'Doe'

    def test_number_of_rows(self):
        assert len( == 4

    def test_iterate_through_rows(self):
        for row in
            assert hasattr(row, 'last_name') 

    def tearDown(self):

The Container class is looking for a "driver" attribute in an owner class, but you can change that behaviour by overiding the attribute driver_attribute from the Container class.

class UserItems(Container):
    item = UserItem()
    rows_locator = ("css selector", "tbody > tr")
    headers_locator = ("css selector", "tbody > tr")    
    driver_attribute = "selenium"

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-datatable, version 0.3.0
Filename, size File type Python version Upload date Hashes
Filename, size selenium_datatable-0.3.0-py3-none-any.whl (11.1 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size (16.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