Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
Is there any way I can use index inside a cy.get('k")?

I have a table like structure where each cell takes some input. The html tag has id something like id="code[0].name", id="code[0].age", ..., and so on.Similarly, id="code[1].name", id="code[1].age", ..., and so on

Now, in cypress, I want to perform something like this,

namesToFetch.forEach( (el,k) => {
   cy.get('[id=code[k].name]').type(name)

My questions is, how to use the k'th index inside the cy.get()?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can use:

namesToFetch.forEach( (el,k) => {
   cy.get(`[id=code[${k}].name]`).type(name)

Or, you could use:

namesToFetch.forEach( (el,k) => {
   cy.get('[id=code[' + k + '].name]').type(name)
about 4 years ago · Juan Pablo Isaza Report

0

You can wild-card the matching selector

cy.get('input[id$="name"]')  // elements with id attribute ENDING WITH name
  .each(($el,idx) => {
    cy.wrap($el).type(namesToFetch[idx])
  })
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!