Reputation: 139
How to use dynamic ID in automation testing
Upvotes: -1
Views: 444
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
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