'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)
})
})
Solution 1:[1]
$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)
})
})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | agoff |
