Testing · Junior · Question 52 of 78

How do you find an input by its label?

<label htmlFor="email">Email</label>
<input id="email" />

Explanation

The query fails if the label isn't connected to the input - a useful accessibility check. getByRole("textbox", { name: "Email" }) works too.

Further reading

Problem with a question

Testing · Junior · question 52

Test yourself

Take the Testing · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz