Skip to main content

Fluent Selectors

A Python library for creating a readable, fluent API for Selenium browser automation.

Installation

Install the package using pip:

pip install fluent-selectors

Usage

Here's a simple example of how to use fluent-selectors:

from selenium import webdriver
from fluent_selectors import ClassNameLocator, IdLocator, NameLocator, Selector

# Initialize the WebDriver
driver = webdriver.Chrome()
driver.get("http://www.python.org")

# Create a Selector instance
s = Selector(driver)

# Select an element and interact with it
search_bar = s.select(NameLocator("q"))
search_bar.set_text("pycon")

go_button = s.select(IdLocator("submit"))
go_button.click()

# Perform checks
assert bool(s.select(ClassNameLocator("list-recent-events")).is_displayed)

driver.quit()

API

Selector(driver: WebDriver, *locators: Locator)

The main class for selecting and interacting with elements.

Traversal and Selection

  • select(locator: Locator) -> Selector: Select a descendant of the current element.
  • child(index: int) -> Selector: Select a child by its index.
  • children() -> list[Selector]: Get a list of all children selectors.
  • parent: Selector | None: The parent selector.
  • parents: list[Selector]: A list of all parent selectors.

Element Actions

  • click(): Clicks the element.
  • type_text(text: str): Types text into the element.
  • clear(): Clears the text from the element.
  • set_text(text: str): Clears the element and then types text into it.
  • upload_file(path: Path): Uploads a file to a file input element.
  • scroll_into_view(): Scrolls the element into view.

Element Properties

  • element: WebElement | None: The Selenium WebElement.
  • elements: list[WebElement]: A list of Selenium WebElements.
  • text: str | None: The text of the element.
  • tag_name: str | None: The tag name of the element.
  • accessible_name: str | None: The accessible name of the element.
  • aria_role: str | None: The ARIA role of the element.
  • id: str | None: The ID of the element.
  • location: Location | None: The location of the element.
  • size: Size | None: The size of the element.
  • attribute(name: str) -> str | None: The value of an attribute.

Checks

These methods return Check objects from the fluent-checks library.

  • is_present: Checks if the element is present in the DOM.
  • is_displayed: Checks if the element is visible.
  • is_enabled: Checks if the element is enabled.
  • is_selected: Checks if the element is selected.
  • is_stale: Checks if the element is stale.
  • has_text(text: str): Checks if the element's text contains the given text.
  • has_exact_text(text: str): Checks if the element's text exactly matches the given text.
  • has_attribute(name: str): Checks if the element has the given attribute.
  • has_attribute_value(name: str, value: str): Checks if the attribute has the given value.

Example of a check:

bool(s.select(IdLocator("my-element")).is_displayed)
bool(s.select(IdLocator("my-element")).has_text("Hello"))

License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.

Release files for fluent-selectors 3.0.0

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

Source distribution (sdist)

Source distribution for fluent-selectors 3.0.0
File Size Uploaded
fluent_selectors-3.0.0.tar.gz 4.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fluent-selectors 3.0.0
File Interpreter ABI Platform
fluent_selectors-3.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 8.7 kB

Release files / fluent_selectors-3.0.0.tar.gz

Download URL fluent_selectors-3.0.0.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e4da7075dace61856a0b85c55fa2e271f2d0a746940b77603d85f00f0bb70aa0
BLAKE2b-256 checksum
How to use checksums
73f8135d5c76c6e0b8dd8966832576f5e05edb41de9782d3c7b6597ba7ae7695
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / fluent_selectors-3.0.0-py3-none-any.whl

Download URL fluent_selectors-3.0.0-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d9dafb8c0d9493fb5d7eb158623975cd7debb814e506ecdd0c50cbb576eee2bf
BLAKE2b-256 checksum
How to use checksums
aa963521dca36414dd96934974c4172d112feeec86bca1ab6f960e0b19b2278a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

3.0.0 This release

2 release files

2.0.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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