Principle:Teamcapybara Capybara Node Filtering
| Knowledge Sources | |
|---|---|
| Domains | Testing, Selector_System |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
A post-query filter mechanism that validates matched DOM elements against criteria that cannot be expressed in CSS or XPath.
Description
Node Filters operate after the DOM query has returned candidate elements. They inspect each element's properties (attributes, computed values, state) in Ruby and filter out non-matching elements. This is necessary for criteria that CSS/XPath cannot express:
- Computed styles or rendered state
- Complex attribute logic
- Cross-element relationships
- Dynamic JavaScript-set properties
Node filters are less efficient than expression filters (they require fetching and inspecting each candidate element) but are more flexible. Non-matching elements are removed from results, and filter errors are collected for failure messages.
Usage
Define node filters inside a selector definition for criteria that require inspecting the actual DOM node. The block receives the node and the filter value, returning a Boolean.
Theoretical Basis
# Abstract node filter flow (not actual code)
node_filter(:checked, :boolean) do |node, value|
node.checked? == value
end
# Pipeline: DOM query -> candidates -> apply node filters -> filtered results