Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:Teamcapybara Capybara Expression Filtering

From Leeroopedia
Revision as of 17:56, 16 February 2026 by Admin (talk | contribs) (Auto-imported from principles/Teamcapybara_Capybara_Expression_Filtering.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Testing, Selector_System
Last Updated 2026-02-12 00:00 GMT

Overview

A pre-query filter mechanism that modifies CSS or XPath expressions based on filter options before the DOM is queried.

Description

Expression Filters narrow the generated selector expression before it hits the DOM, making the initial query more efficient. Instead of fetching all matching elements and filtering in Ruby, expression filters bake filter criteria directly into the CSS/XPath expression.

For example, a :disabled expression filter on the :button selector appends [disabled] to the CSS expression, so the DOM query only returns disabled buttons — rather than returning all buttons and filtering in Ruby.

Expression filters are more efficient than node filters because they reduce the number of elements returned by the driver, but they can only filter on criteria expressible in CSS/XPath.

Usage

Define expression filters inside a selector definition when the filter criteria can be expressed in CSS or XPath. The block receives the current expression and the filter value, and must return a modified expression.

Theoretical Basis

# Abstract expression filter flow (not actual code)
expression_filter(:disabled, :boolean) do |expression, value|
  if value
    expression + "[disabled]"    # narrow CSS before query
  else
    expression + ":not([disabled])"
  end
end

# Pipeline: CSS expression -> apply expression filters -> DOM query

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment