Skip to main content

selenium-datatable

Build Status codecov PyPi

Overview

A small library for simplifying a table object in selenium

Installation

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 setup.py install

Usage

A table object class implementation:

# -- FILE: table.py
from selenium.webdriver.common.by 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: home_page.py
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):
        self.driver.get(self.url)

Unittest:

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

class TestTable(unittest.TestCase):

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

    def test_get_item_from_first_row(self):        
        item = self.page.items_list.get_item_by_position(1)        
        self.assertEqual(item.first_name.text, 'John')
        self.assertEqual(item.last_name.text, 'Smith')
        self.assertEqual(item.email.text, 'jsmith@gmail.com')
    
    def test_get_item_by_property(self):
        item = self.page.items_list.get_item_by_property(last_name='Doe', first_name='Jason')    
        self.assertEqual(item.first_name.text, 'Jason')
        self.assertEqual(item.last_name.text, 'Doe')
    
    def test_number_of_rows(self):
        assert len(self.page.items_list) == 4
    
    def test_iterate_through_rows(self):
        for row in self.page.items_list:
            self.assertTrue(hasattr(row, 'last_name')) 
    
    def test_comprehension_list_slice(self):
        users = [row for row in self.page.items_list[1:3]]
        self.assertEqual(len(users), 2)
        self.assertEqual(users[0].first_name.text, "Frank")
        self.assertEqual(users[1].first_name.text, "Jason")

    def tearDown(self):
        self.driver.close()

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

class UsersTable(DataTable):
    ...
    driver_attribute = "selenium"

Metadata

Release files for selenium-datatable 0.3.3

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 selenium-datatable 0.3.3
File Interpreter ABI Platform Actions
selenium_datatable-0.3.3-py3-none-any.whl Python 3 none any Details for selenium_datatable-0.3.3-py3-none-any.whl

Release files / selenium_datatable-0.3.3-py3-none-any.whl

Download URL selenium_datatable-0.3.3-py3-none-any.whl
Size 11.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cadbb43a8b65b2f4e987a155b22dda656869a1e6e055e43c8cc9f5e7eb22ec86
BLAKE2b-256 checksum
How to use checksums
4f50ce39199fd46adff606bc2ef6a0e6dd52f6f4097043d198a84a91d5456e8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.0

Security for selenium-datatable 0.3.3

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.

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