Repository navigation
Support Capybara's finder hints in find_css and find_xpath - #347
Open
joeljunstrom wants to merge 1 commit into
Open
joeljunstrom wants to merge 1 commit into
joeljunstrom wants to merge 1 commit into
Conversation
Capybara passes uses_visibility, texts, styles and position to finders that take them and reads the answers from Node#initial_cache. Without them it asked each candidate for its visibility and text in round trips of its own. One callFunctionOn returns each node behind its answers as JSON, read from the array's handle with getProperties, since Ferrum only resolves arrays that hold nothing but nodes. Texts drop a node only when neither all its text nor its visible text holds them, case sensitively, as Capybara matches. Browser#find and #find_within still return nodes.
joeljunstrom
force-pushed
the
find-hints
branch
from
October 19, 2026 09:17
55406ce to
5ed6188
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Capybara passes
uses_visibility,texts,stylesandpositionto drivers whose finders accept them, and reads the answers fromNode#initial_cache. Cuprite's finders took only the selector, so Capybara asked every candidate for its visibility and text separately, about 8 CDP commands per node.The browser now answers the hints in the same call that finds the nodes. It returns each node with its answers as JSON, read from the array's handle, so nodes and answers can't come from different pages. Ferrum only resolves arrays that hold nothing but nodes, which is why the handle is read directly.
Text is filtered case-sensitively against all text or visible text, the strings Capybara compares, so nothing Capybara would match is dropped. Selenium's lowercased
textContentfilter misses a word split by a hidden element.On a list of 300 items, every third one hidden:
find("li", text: "Item 298")all("li", minimum: 1)assert_selector("li", text: "Item 2", count: 75)first("li", text: "Item 298", below: …)In a (well my) Rails app's suite the gain is smaller: about 10–20% fewer commands per test, with no measurable wall-time change, because most finds match few elements.
Browser#findand#find_withinstill return nodes.