Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cypress img elements attribute checking

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?

like image 966
nigel Avatar asked Sep 09 '26 21:09

nigel


1 Answers

To check each element, you can use .each:

cy.get('img').each($el => {
  cy.wrap($el).should('have.attr', 'alt')
}
like image 65
bkucera Avatar answered Sep 11 '26 10:09

bkucera



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!