最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Cypress img elements attribute checking - Stack Overflow

programmeradmin2浏览0评论

I need to check if all images on my page have the Alt attribute. I thought doing the following would do that but it doesn't check things correctly and just gives me an everything is good when I know it's not. cy.get('img').should('have.attr', 'alt' );

Is there an easy solution other than many go through the page and build a selector for every image?

I need to check if all images on my page have the Alt attribute. I thought doing the following would do that but it doesn't check things correctly and just gives me an everything is good when I know it's not. cy.get('img').should('have.attr', 'alt' );

Is there an easy solution other than many go through the page and build a selector for every image?

Share Improve this question asked Mar 7, 2019 at 12:47 nigelnigel 1813 silver badges11 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 7

To check each element, you can use .each:

cy.get('img').each($el => {
  cy.wrap($el).should('have.attr', 'alt')
}
发布评论

评论列表(0)

  1. 暂无评论