Skip to main content

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

Project description

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
s.select(ClassNameLocator("list-recent-events")).is_displayed.is_true()

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:

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

License

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

Project details


Download files

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

Source Distribution

fluent_selectors-1.1.1.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fluent_selectors-1.1.1-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file fluent_selectors-1.1.1.tar.gz.

File metadata

  • Download URL: fluent_selectors-1.1.1.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for fluent_selectors-1.1.1.tar.gz
Algorithm Hash digest
SHA256 9eb2404f036e8f28754c6b0269552aee63b4fc7241ad6487f583dca875706d7e
MD5 029234cf6c47a9d2c05982ff84aa89c7
BLAKE2b-256 8362ad4fa1c0bf8bb79f0fb522ed06f612e58e56eecb372506a407451864003b

See more details on using hashes here.

File details

Details for the file fluent_selectors-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: fluent_selectors-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for fluent_selectors-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 55e9e4e3f241e93ecf4ccc7edc331ae67027ef990eaff232c6db192eeab67fa9
MD5 d52a38263d7a5d0409d108df0ca05851
BLAKE2b-256 65d8ca4e86e48ee2f8929c7161884a38f85ec30bed673d87ea844b3c54663ae0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page