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.

Implementation:Teamcapybara Capybara Chrome Node

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

Overview

Concrete tool for Chrome-specific DOM node interaction with text input quirks, file handling, emoji support, and native display checking, provided by Capybara::Selenium::ChromeNode.

Description

Capybara::Selenium::ChromeNode inherits from Capybara::Selenium::Node and includes the Html5Drag and FileInputClickEmulation modules. It overrides several methods to handle Chrome and ChromeDriver-specific behavior.

set_text calls super and then, if the value is empty and no explicit clear strategy was given, sends :space followed by :backspace to work around a React compatibility issue where ChromeDriver's element clearing is not detected by React's event system.

set_file handles a Chrome 75+ behavior where the WebDriver spec causes files to be appended to multi-file inputs rather than replaced. Before calling super, it executes JavaScript to null out the input's value if the input is multiple and already has files set.

click rescues WebDriverError and re-raises it as ElementClickInterceptedError when the message contains "'element click intercepted'", working around ChromeDriver 74's incorrect error class on macOS.

disabled? uses a JavaScript CSS selector (:disabled, select:disabled *) instead of the default WebDriver attribute check, which correctly identifies options within disabled select elements.

select_option optimizes selection to a single JavaScript check for :disabled, select:disabled *, :checked and only clicks if the option is neither disabled nor already selected.

visible? leverages Chrome's native is_element_displayed endpoint when available (ChromeDriver >= 76.0.3809.25), falling back to the standard implementation if the command is unknown. This optimization is disabled when native_displayed is set to false or DISABLE_CAPYBARA_SELENIUM_OPTIMIZATIONS is set.

send_keys chunks input arguments by whether they contain emoji presentation characters. Emoji clusters are sent via the CDP Input.insertText command, while non-emoji text uses the standard send_keys path.

Usage

Automatically instantiated by the Chrome driver specialization via build_node. No direct user construction required.

Code Reference

Source Location

  • Repository: capybara
  • File: lib/capybara/selenium/nodes/chrome_node.rb
  • Lines: 135

Signature

class Capybara::Selenium::ChromeNode < Capybara::Selenium::Node
  include Html5Drag
  include FileInputClickEmulation

  def set_text(value, clear: nil, **_unused)
    # @param value [String] Text value to set
    # @param clear [Symbol, nil] Clear strategy (:backspace, :none, nil)
  end

  def set_file(value)
    # @param value [String, Array<String>] File path(s) to attach
  end

  def drop(*args)
    # @param args [Array] File paths or type/data pairs for HTML5 drop
  end

  def click(*, **)
    # Delegates to super; re-raises correct error for ChromeDriver 74
  end

  def disabled?
    # @return [Boolean] True if element matches :disabled or is within a disabled select
  end

  def select_option
    # Clicks the option unless it is already selected or disabled
  end

  def visible?
    # @return [Boolean] Uses native displayed endpoint when available
  end

  def send_keys(*args)
    # @param args [Array<String, Symbol>] Keys to send; emoji handled via CDP
  end
end

Import

require 'capybara/selenium/nodes/chrome_node'
# Loaded automatically by the Chrome driver specialization

I/O Contract

Inputs

Name Type Required Description
value (set_text) String Yes Text value to set on the element
clear (set_text) Symbol/nil No Clear strategy: :backspace, :none, or nil (default)
value (set_file) String/Array<String> Yes One or more file paths to attach
args (drop) Array Yes File paths (String) or type/data pairs (Hash) for HTML5 drop
args (send_keys) Array<String, Symbol> Yes Key inputs; emoji characters routed through CDP Input.insertText

Outputs

Name Type Description
disabled? Boolean Whether the element is disabled (including options in disabled selects)
visible? Boolean Whether the element is displayed, using native endpoint when possible

Usage Examples

Text Input with React Workaround

# Setting an empty value triggers space+backspace for React compatibility
chrome_node.set_text('')

# Setting a value with explicit clear strategy
chrome_node.set_text('hello', clear: :backspace)

File Upload

file_input = page.find('input[type="file"]')

# Single file - clears existing files on Chrome 75+ multi-file inputs
file_input.set('/path/to/file.pdf')

# Multiple files
file_input.set(['/path/to/file1.pdf', '/path/to/file2.pdf'])

Emoji Input via CDP

input = page.find('#emoji-field')

# Emoji characters are sent via CDP Input.insertText
input.send_keys('Hello ', "\u{1F600}", ' World')

Drag and Drop

source = page.find('#drag-source')
target = page.find('#drop-target')

# HTML5 drag-and-drop (via included Html5Drag module)
source.drag_to(target)

# Programmatic file drop
target.drop('/path/to/file.txt')

Related Pages

Implements Principle

Requires Environment

Page Connections

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