Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:Teamcapybara Capybara Selector Modification

From Leeroopedia
Knowledge Sources
Domains Testing, Selector_System
Last Updated 2026-02-12 00:00 GMT

Overview

An extension pattern that reopens an existing selector definition to add new filters or modify behavior without replacing it.

Description

Selector Modification allows extending built-in or previously defined selectors without replacing their entire definition. This is useful for:

  • Adding domain-specific filters to Capybara's built-in selectors (e.g., filtering buttons by style class)
  • Augmenting third-party selectors
  • Progressively building up selector capabilities

The modification block is evaluated via instance_eval on the existing Definition object, so it has access to all DSL methods (expression_filter, node_filter, label, etc.).

Usage

Use Capybara.modify_selector to add filters to existing selectors. This is preferred over redefining a selector from scratch when you only need to add functionality.

Theoretical Basis

# Abstract modification pattern (not actual code)
modify_selector(:button) do
  node_filter(:style) do |node, value|
    node[:class].include?("btn-#{value}")
  end
end
# Now: find(:button, 'Submit', style: :primary) works

Related Pages

Implemented By

Page Connections

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