teamcapybara/capybara · error · Capybara::ModalNotFound

Unable to find modal dialog with #{text} - found '#{alert.te

Error message

Unable to find modal dialog with #{text} - found '#{alert.text}' instead.

What it means

Error "Unable to find modal dialog with #{text} - found '#{alert.text}' instead." thrown in teamcapybara/capybara.

Source

Thrown at lib/capybara/selenium/driver.rb:411

      switch_to_window(original_handle)
      result
    end
  end

  def find_modal(text: nil, **options)
    # Selenium has its own built in wait (2 seconds)for a modal to show up, so this wait is really the minimum time
    # Actual wait time may be longer than specified
    wait = Selenium::WebDriver::Wait.new(
      timeout: options.fetch(:wait, session_options.default_max_wait_time) || 0,
      ignore: modal_error
    )
    begin
      wait.until do
        alert = @browser.switch_to.alert
        regexp = text.is_a?(Regexp) ? text : Regexp.new(Regexp.escape(text.to_s))
        matched = alert.text.match?(regexp)
        unless matched
          raise Capybara::ModalNotFound, "Unable to find modal dialog with #{text} - found '#{alert.text}' instead."
        end

        alert
      end
    rescue *find_modal_errors
      raise Capybara::ModalNotFound, "Unable to find modal dialog#{" with #{text}" if text}"
    end
  end

  def find_modal_errors
    @find_modal_errors ||= [Selenium::WebDriver::Error::TimeoutError]
  end

  def silenced_unknown_error_message?(msg)
    silenced_unknown_error_messages.any? { |regex| msg.match? regex }
  end

  def silenced_unknown_error_messages

View on GitHub (pinned to 15b5fdb76e)

When it happens

Trigger: Thrown at lib/capybara/selenium/driver.rb:411 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of teamcapybara/capybara@15b5fdb76e (2026-08-21). Data as JSON: /api/errors/f55ad1bcbcf3cdac. Report an issue: GitHub.