Rajesha T R
Rajesha T R

Reputation: 13

How to get length data from a given array?

Query URL - "XYZ "

From the above URL we can see different category's like a, b & c.

Now, my question is how we can get the length present in each category and display in the output?

For example c has 13 count listed, This I want to show case using cypress code.

Upvotes: 1

Views: 201

Answers (1)

Alapan Das
Alapan Das

Reputation: 18624

You can iterate over the tab sections using each(), perform a click, and then calculate the length of all the questions. A simple program demonstrating that -

it('Print the Number of Questions in each Tab', function() {
  cy.visit('https://www.kreditbee.in/faq')
  cy.get('button[role="tab"]').each(($ele) => {
    cy.wrap($ele).click()
    cy.get('svg').its('length').then((len) => {
      cy.log('The number of questions in ' + $ele.text() + ' tab: ' + len)
    })
  })
})

Successful Execution

Upvotes: 1

Related Questions