Skip to main content

Selenium Tabs

A Python library that makes browser automation with Selenium more intuitive by providing a tab-centric interface. Manage multiple browser tabs with ease, perform common operations, and interact with web elements using a clean, Pythonic API.


And guess what! You don't need to manually download drivers for the browser—it's all taken care of by the library. Install and start right away.

Note: Local automated tests are designed for Chrome and run headless when Chrome is available.

🚀 Top Features

  • Tab Management: Open, close, switch, and query tab state with ease.
  • Element Selection: Use CSS selectors, jQuery, and PyQuery for powerful element querying.
  • Page Interaction: Scroll, click, and wait for elements with robust error handling.
  • Advanced Features: Direct driver access, task scheduling, and more.
  • Automatic Driver Management: No need to manually download or manage browser drivers.

🔧 Installation

pip install seleniumtabs

For local development with uv:

git clone https://github.com/inquilabee/selenium-tabs.git
cd selenium-tabs
uv sync --all-groups

📋 Requirements

  • Python 3.13+
  • Chrome or Firefox browser

🛠️ Development

This project uses uv and PEP 621 package metadata in pyproject.toml.

make sync          # install runtime and development dependencies
make test          # run the default deterministic test suite
make integration   # run live browser/network tests
make check-commit  # run the fast local quality gate
make lint          # run all pre-commit hooks
make build         # build wheel and sdist

Default tests use local HTML fixtures from tests/fixtures/pages/ and exclude integration tests. Live-site tests are marked with @pytest.mark.integration because they require Chrome, network access, and external websites that may change.

Before publishing, configure PyPI Trusted Publishing for this GitHub repository, the publish workflow, and the pypi environment. Releases build with uv build and publish with uv publish from GitHub Actions.

🚀 Quick Start

from seleniumtabs import Browser

# Create a browser instance and open multiple tabs
with Browser(name="Chrome", implicit_wait=10) as browser:
    # Open multiple websites in different tabs
    google = browser.open("https://google.com")
    yahoo = browser.open("https://yahoo.com")

    # Work with tabs
    print(f"Current tab: {browser.current_tab}")
    print(f"First tab: {browser.first_tab}")
    print(f"Last tab: {browser.last_tab}")

    # Switch between tabs
    yahoo.switch()
    google.switch()

    # Close a tab
    yahoo.close()

✨ Key Features

1. Tab Management

with Browser(name="Chrome") as browser:
    # Open tabs
    tab1 = browser.open("https://example.com")
    tab2 = browser.open("https://example.org")

    # Access tab properties
    print(tab1.title)  # Page title
    print(tab1.url)    # Current URL
    print(tab1.domain) # Domain name

    # Check tab state
    print(tab1.is_active)  # Is this the active tab?
    print(tab1.is_alive)   # Is the tab still open?

2. Element Selection

with Browser(name="Chrome") as browser:
    tab = browser.open("https://example.com")

    # CSS Selectors
    elements = tab.css("div.class-name")
    for element in elements:
        print(element.text)

    # Chaining selectors
    main_content = tab.css("main")[0]
    links = main_content.css("a")

    # Get element attributes
    for link in links:
        print(link.get_attribute("href"))

3. Page Interaction

with Browser(name="Chrome") as browser:
    tab = browser.open("https://example.com")

    # Scrolling
    tab.scroll_down(times=3)  # Scroll down 3 times
    tab.scroll_up(times=2)    # Scroll up 2 times
    tab.scroll_to_bottom()    # Scroll to page bottom

    # Clicking elements
    element = tab.css("button")[0]
    tab.click(element)

    # Wait for elements
    tab.wait_for_presence("div", "class-name", wait=10)
    tab.wait_for_visibility("button", "submit", wait=5)

4. Advanced Features

with Browser(name="Chrome") as browser:
    tab = browser.open("https://example.com")

    # jQuery-like operations
    jq_elements = tab.jq("div.class-name")

    # PyQuery for HTML parsing
    pq = tab.pyquery
    text_content = pq.text()

    # Run JavaScript
    result = tab.run_js("return document.title")

    # Schedule tasks
    def refresh_page(tab):
        tab.refresh()

    tab.schedule_task(refresh_page, period=60)  # Refresh every 60 seconds

Direct Driver Access

  • If a feature is not directly available in the Tab object, you can access the underlying Selenium WebDriver directly via tab.driver.

  • Example:

    # Access driver methods directly
    tab.driver.execute_script("return document.title")
    
  • Fallback Behavior: If you call a non-existent method on the Tab object, an attempt is made to query tab.driver.method_name via __getattribute__.

jQuery Integration

  • You can use the tab.jq or tab.jquery property to run jQuery-like selectors and operations directly on the live browser DOM.
  • Tested features:
    • Selecting elements with jQuery syntax.
    • Chaining jQuery selectors.
    • Accessing and manipulating attributes and text.
    • Interacting with elements (e.g., click, scroll).

Example:

jq_elements = tab.jq("div.class-name")
for el in jq_elements:
    print(el.text)

PyQuery Integration

  • You can use the tab.pyquery or tab.pq property to parse and query the current page's HTML snapshot using PyQuery (lxml-based).
  • Tested features:
    • .items() for iterating over selections and sub-selections.
    • .find(), .parent(), .children() for DOM navigation.
    • .attr(), .text(), .html() for attribute and content access.
    • Consistency between tab.pyquery and tab.pq.
    • Integration with real-world pages (e.g., Yahoo).

Example:

pq = tab.pyquery
for link in pq("nav a").items():
    print(link.attr("href"))
print(pq("title").text())

🔍 Browser Options

with Browser(
    name="Chrome",           # Browser name ("Chrome" or "FireFox")
    implicit_wait=10,        # Default wait time for elements
    headless=False,          # Run browser in headless mode
    full_screen=True,        # Start browser in full screen
    page_load_timeout=60     # Page load timeout in seconds
) as browser:
    # Your code here

✅ Tested Features

This library is thoroughly tested for:

  • Tab Management: Opening, closing, switching, and querying tab state.
  • Element Selection: CSS selector queries, chaining, and attribute access.
  • Page Interaction: Scrolling, clicking, and waiting for elements.
  • Page Loading: Full and partial page load handling, including timeouts.
  • Tab Refresh: Full and partial refresh with robust error handling.
  • Task Scheduling: Periodic tab actions (e.g., auto-refresh).
  • Integration with jQuery and PyQuery (see below).

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for seleniumtabs 2.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for seleniumtabs 2.1.2
File Size Uploaded Provenance
seleniumtabs-2.1.2.tar.gz 23.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for seleniumtabs 2.1.2
File Interpreter ABI Platform
seleniumtabs-2.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 47.1 kB

Release files / seleniumtabs-2.1.2.tar.gz

Download URL seleniumtabs-2.1.2.tar.gz
Size 23.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c8ac262239a57f80492dd1b966386488ba0930fae1ce2e3658d817ba19def800
BLAKE2b-256 checksum
How to use checksums
3509e11259fe015d40b77dbe4f0b7c4fda73b4767c0b43c1d1428799bdaf6819
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / seleniumtabs-2.1.2-py3-none-any.whl

Download URL seleniumtabs-2.1.2-py3-none-any.whl
Size 23.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
82fc9b2ec7422f1ae1ae5ce8711654100a9885460d39f40f315038b8899d17c7
BLAKE2b-256 checksum
How to use checksums
88cdd4ae8ac4637191c2cf069b8d31dc2eaac1258e35a1ab54dfed42da6e550a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for seleniumtabs 2.1.2

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.

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