← Back to library
Cypressassertionsintermediatev10+

Assert element attributes

Check href, aria-label, disabled state, and data attributes on elements.

1it('link and button attributes are correct', () => {
2  cy.visit('/profile');
3
4  cy.get('a[data-testid="docs-link"]')
5    .should('have.attr', 'href')
6    .and('include', '/docs');
7
8  cy.get('[data-testid="avatar"]')
9    .should('have.attr', 'aria-label', 'User avatar');
10
11  cy.get('[data-testid="submit-btn"]')
12    .should('not.be.disabled');
13
14  cy.get('[data-testid="plan-badge"]')
15    .should('have.attr', 'data-plan', 'pro');
16});
#attribute#aria#disabled#href#have.attr