2

I'm using Gauge/Taiko to automate some scenarios and I'm struggling with some basic stuff.

Given a selector that match N elements: is there a way to list/count those elements? Today even I provide a selector that matchs N elements, it returns only the 1st match.

example:

$('.input')

returns only the first element with the class input

par
  • 817
  • 8
  • 21

1 Answers1

8

To just find the number of matching elements (await $('#id').get()).length can be used, to access element by index there is an open issue for the same https://github.com/getgauge/taiko/issues/288

Update:

get() is now deprecated in taiko. And taiko supports accessing elements by index. Do use (await $('#id').elements()).length

par
  • 817
  • 8
  • 21
  • 1
    Upvote this answer and adding that for anyone that is trying to assert on count, you need to use direct node `assert`: `assert.equal((await text(`MY LABEL`).elements()).length, 2)`. See: https://nodejs.org/api/assert.html#assert_assert_equal_actual_expected_message – Charles Chen Jul 16 '20 at 13:54