Skip to content

Ambigous checkbox match even with automatic_label_click=true #2806

@freesteph

Description

@freesteph

Hello, this is Capybara 3.40 running in Selenium. I've got some markup like this:

<input type="checkbox" name="audit[questions][chaussures-lacets][criteria][]" id="audit_q0_c0" value="yes" />
<label for="audit_q0_c0">Le lacet gauche est attaché au lacet droit</label>

But when I try to check("Le lacet gauche est attaché au lacet droit") I get

Ambiguous match, found 2 elements matching visible checkbox "Le lacet gauche est attaché au lacet droit" that is not disabled (Capybara::Ambiguous)

Now here's a debugger-REPL to explore the markup together. The page contains 4 checkboxes, but the others have different labels and different for/id attributes:

(rdbg) page.config.automatic_label_click
true

(rdbg) page.body.lines.grep /type=\"checkbox\"/
["<input type=\"checkbox\" name=\"audit[questions][chaussures-lacets][criteria][]\" id=\"audit_q0_c0\" value=\"yes\" />\n",
 "<input type=\"checkbox\" name=\"audit[questions][chaussettes-pareilles][criteria][]\" id=\"audit_q0_c0\" value=\"yes\" />\n",
 "<input type=\"checkbox\" name=\"audit[questions][chaussettes-pareilles][criteria][]\" id=\"audit_q0_c1\" value=\"yes\" />\n",
 "<input type=\"checkbox\" name=\"audit[questions][chaussettes-pareilles][criteria][]\" id=\"audit_q0_c2\" value=\"yes\" />\n"]

(rdbg) page.body.lines.grep /<label/
["<label for=\"audit_q0_c0\">Le lacet gauche est attaché au lacet droit</label>\n",
 "<label for=\"audit_q0_c0\">J&#39;ai une chaussette sur mon pied gauche</label>\n",
 "<label for=\"audit_q0_c1\">J&#39;ai une chaussette sur mon pied droit</label>\n",
 "<label for=\"audit_q0_c2\">Les deux chaussettes sont de la même famille</label>\n"]


(rdbg) page.check("Le lacet gauche est attaché au lacet droit")
eval error: Ambiguous match, found 2 elements matching visible checkbox "Le lacet gauche est attaché au lacet droit" that is not disabled

Can you help me figure out what I'm doing wrong?

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