user3537901
user3537901

Reputation: 139

Cypress entering text into a dynamic ID search box

How to use dynamic ID in automation testing

Upvotes: -1

Views: 444

Answers (2)

jjhelguero
jjhelguero

Reputation: 2555

It would make your test more stable if you could add a data-testid to your input. If not, you use an attribute unique to the input it would really depend on your pages' DOM.

Some possibilities.

cy.get('input[placeholder]')
cy.get('input[autocomplete]')
cy.get('input[data-key]')
cy.get('input[value]')
// you can combine the above to make them more unique

Upvotes: 0

Alapan Das
Alapan Das

Reputation: 18634

You can use the aria-label for this like:

cy.get('input[aria-label="main-search-box-ui-lib-container"]').type('text')

Upvotes: 1

Related Questions