Skip to content

Cuprite finding elements inside closed detail tags #184

Closed

Description

@brenogazzola

I'm in the process of replacing selenium with cuprite for my Rails system tests. I have a green CI with selenium, but when I switch to cuprite I start getting a lot of errors like this:

Test:

within ".modal-body-confirmation" do
  click_button "Yes, delete"
end

Message

Capybara::Ambiguous: Ambiguous match, found 3 elements matching visible css ".modal-body-confirmation"

After checking, I discovered that I had 3 .modal-body-confirmation elements inside 3 different detail tags, but only 1 of those tags was open. So it seems that this file used for the specs needs to be updated to include a test for closed detail tags.

This is an extraction of what the HTML looked like at the failure. You can see 2 modal-body-confirmation but only whose parent detail element is open.

<details open="">
  <summary class="modal-trigger">
    <button class="" title="Recomeçar lista de presentes"><span>Recomeçar lista de presentes</span></button>
  </summary>
  <div class="modal-content pos-1001">
    <div class="modal-body modal-body-confirmation">
      <!-- Redacted -->
    </div>
  </div>
</details>

<details>
  <summary class="modal-trigger">
    <div class="" title="Remover loja"><span>Remover loja</span></div>
  </summary>
  <div class="modal-content pos-1001">
    <div class="modal-body modal-body-confirmation">
      <!-- Redacted -->
    </div>    
  </div>
</details>

Activity

  1. route commented on Oct 16, 2026

    @route
    Member

    Fixed by #317 in Cuprite 0.18. Content of a closed <details> other than its first <summary> is no longer considered visible, and Capybara's shared specs for this run in Cuprite's suite now.

    With your markup (one open and two closed <details>), all(".modal-body-confirmation") finds 1 visible element out of 3. within(".modal-body-confirmation") { click_button "Yes, delete" } clicks the button in the open one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions