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

214
Views
Accessing href attribute using invoke() in each() Cypress

I am new to Cypress and I'm trying to access the href attribute for each div tag from a group using invoke() but it gives error. Can someone suggest how you do it?

cy.get('.bms-scoreboard__game-tile--mls').each(($el,index,$list) => {
            $el.get('a')
                .invoke('attr','href')
                .then(href => {
                    cy.request(href)
                        .its('status')
                        .should('eq',200)
                })
        })
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I don't think .get() is appropriate - it only works from the <body> not from each '.bms-scoreboard__game-tile--mls'.

Try .find() instead

With jQuery operators

cy.get('.bms-scoreboard__game-tile--mls')
  .each(($el,index,$list) => {
    const href = $el.find('a').attr('href')
    cy.request(href)
      .its('status')
      .should('eq', 200)
  })
})

or with Cypress operators

cy.get('.bms-scoreboard__game-tile--mls')
  .each(($el,index,$list) => {
    cy.wrap($el).find('a')
      .invoke('attr','href')
      .then(href => {
        cy.request(href)
           .its('status')
           .should('eq',200)
      })
  })
})

or move "find" into first selector

cy.get('.bms-scoreboard__game-tile--mls a')
  .each($a => {
    const href = $a.attr('href')
    cy.request(href)
      .its('status')
      .should('eq', 200)
  })
})
about 4 years ago · Juan Pablo Isaza Report

0

$el is a JQuery element, and not itself in the Cypress chain. You'll need to use cy.wrap() to use it in a Cypress chain.

cy.get('.bms-scoreboard__game-tile--mls').each(($el,index,$list) => {
            cy.wrap($el)
                .get('a')
                .invoke('attr','href')
                .then(href => {
                    cy.request(href)
                        .its('status')
                        .should('eq',200)
                })
        })
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!