Playwright · Junior · Question 22 of 75

How do you pick the second row of a list deliberately?

Show the answer

Correct answer: page.getByRole('listitem').nth(1)

Explanation

nth() is zero-based, with first() and last() as shortcuts. Prefer filtering by content when possible, since order can change.

Further reading

Problem with a question

Playwright · Junior · question 22

Test yourself

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

Take this quiz