From 347dfcca87ab2201a61054904cac76b37a1fbb35 Mon Sep 17 00:00:00 2001 From: Dmitry Vorotilin Date: Fri, 16 Oct 2026 13:06:27 +0300 Subject: [PATCH] fix(driver): send keys to the focused element without clicking it --- CHANGELOG.md | 3 +++ lib/capybara/cuprite/driver.rb | 6 +++++- spec/spec_helper.rb | 1 - 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8c180b..7ff712b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ - Ferrum is bumped to `~> 0.19.0` ### Fixed +- `Driver#send_keys` clicked the focused element before typing, so `send_keys(:tab)` from `` clicked the middle of + the page and Tab moved focus from there instead of to the first element. It types into the focused element now, and + Capybara's `#active_element` and `focused:` specs run in the suite - `window_size: nil` raised `Ferrum::BrowserError: Invalid parameters` on every page instead of leaving the window size to Chrome, so `start-maximized` couldn't be used [#278] - `Driver#reset!` kept the page it had cached when the browser failed to reset, so every later example raised diff --git a/lib/capybara/cuprite/driver.rb b/lib/capybara/cuprite/driver.rb index 2214383..2dc57d7 100644 --- a/lib/capybara/cuprite/driver.rb +++ b/lib/capybara/cuprite/driver.rb @@ -15,7 +15,6 @@ class Driver < Capybara::Driver::Base delegate %i[restart quit status_code timeout timeout= current_url title body window_handles close_window switch_to_window within_window window_handle back forward refresh wait_for_reload viewport_size device_pixel_ratio] => :browser - delegate %i[send_keys] => :active_element alias html body alias current_window_handle window_handle alias go_back back @@ -75,6 +74,11 @@ def active_element Node.new(self, browser.active_element) end + def send_keys(*keys) + keys = keys.reject { |key| key.nil? || key == "" } + browser.page.keyboard.type(keys) unless keys.empty? + end + def find_xpath(selector) find(:xpath, selector) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c5986b5..74f9f6e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -63,7 +63,6 @@ module TestSessions metadata[:skip] = true if metadata[:full_description].match(/#{regexes}/) metadata[:skip] = "Intentionally skipped" if metadata[:full_description].match(/#{intentional_skip}/) - metadata[:skip] = true if metadata[:requires]&.include?(:active_element) end config.around do |example|