From a70044287ec701f15c1faeb2dfbcba62740127d5 Mon Sep 17 00:00:00 2001 From: David Biddle Date: Thu, 6 Aug 2026 12:16:14 +0100 Subject: [PATCH 1/2] Fix intermittent selenium error Add the 'disable-features=DeferRendererTasksAfterInput' flag, which resolves a longstanding issue with Selenium throwing intermittent errors (https://github.com/teamcapybara/capybara/issues/2800) --- spec/spec_helper.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8514686..db5a41b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -36,6 +36,8 @@ options.add_preference(:browser, set_download_behavior: { behavior: "allow" }) + options.add_argument("--disable-features=DeferRendererTasksAfterInput") + Capybara.register_driver :chrome do |app| Capybara::Selenium::Driver.new(app, browser: :chrome, options: options) end From c21c082dd380553adf7f882e7efbc7be8dcc9c24 Mon Sep 17 00:00:00 2001 From: David Biddle Date: Thu, 6 Aug 2026 12:17:08 +0100 Subject: [PATCH 2/2] Remove Selenium error patch This patch is no longer needed as the `disable-features=DeferRendererTasksAfterInput` flag resolves the issue this is patching. --- spec/spec_helper.rb | 1 - spec/support/selenium_error_patch.rb | 34 ---------------------------- 2 files changed, 35 deletions(-) delete mode 100644 spec/support/selenium_error_patch.rb diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index db5a41b..a145945 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -28,7 +28,6 @@ end else require "selenium/webdriver" - require_relative "support/selenium_error_patch" options = Selenium::WebDriver::Chrome::Options.new options.add_preference(:download, prompt_for_download: false, diff --git a/spec/support/selenium_error_patch.rb b/spec/support/selenium_error_patch.rb deleted file mode 100644 index 57f8c07..0000000 --- a/spec/support/selenium_error_patch.rb +++ /dev/null @@ -1,34 +0,0 @@ -# Monkey patch for a specific intermittent Selenium error. -# -# Intermittently, Selenium/Chromedriver raises `Selenium::WebDriver::Error::UnknownError` -# with the message "Node with given id does not belong to the document". - -# Capybara's automatic waiting/retrying mechanism doesn't catch it, -# leading to failure. -# -# We intercept the initialization of `UnknownError`. If the message matches this specific -# case, we raise a `StaleElementReferenceError` instead. This uses Capybara's -# retry logic which makes doesn't fail the test -# -# This can be removed once the following issue is resolved: -# https://github.com/teamcapybara/capybara/issues/2800 -# -# taken from the following issue: -# https://github.com/teamcapybara/capybara/issues/2800#issuecomment-3049956982 - -module Selenium - module WebDriver - module Error - class UnknownError - alias_method :old_initialize, :initialize - def initialize(msg = nil) - if msg&.include?("Node with given id does not belong to the document") - raise StaleElementReferenceError, msg - end - - old_initialize(msg) - end - end - end - end -end