admin管理员组文章数量:1416651
cy.get('div.infoTextCarousel').find('a.ProductInfoAnchor').should('have.attr', 'href', url)
There are many divs with the same name 'div.infoTextCarousel' and within each there is 'a.ProductInfoAnchor' one of them contains matching href. So what I want is that cypress keep looking for the matching href until it'll be found, but the problem is that it only checks first 'div.infoTextCarousel' and within 'a.ProductInfoAnchor' when it's not able to found the matching href it fails.
cy.get('div.infoTextCarousel').find('a.ProductInfoAnchor').should('have.attr', 'href', url)
There are many divs with the same name 'div.infoTextCarousel' and within each there is 'a.ProductInfoAnchor' one of them contains matching href. So what I want is that cypress keep looking for the matching href until it'll be found, but the problem is that it only checks first 'div.infoTextCarousel' and within 'a.ProductInfoAnchor' when it's not able to found the matching href it fails.
Share Improve this question asked Jul 17, 2019 at 9:34 JunaidJunaid 6747 gold badges18 silver badges37 bronze badges1 Answer
Reset to default 2You can pass a callback function to a should() in case you need some more sophisticated behaviour. In the below code I am extracting the href attributes, and expecting the list of attributes to contain a specific url:
const url = '/something'
cy.get('div.infoTextCarousel')
.find('a')
.should($a => {
let hrefs = $a.map((i, el) => {
return Cypress.$(el).attr('href')})
expect(hrefs.get()).to.contain(url)
})
Hope this helps.
本文标签: javascriptCypresshow to iterate through elementsStack Overflow
版权声明:本文标题:javascript - Cypress, how to iterate through elements? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745254896a2650041.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论