I am trying to enter text in the search box field however, the search box field only has one selector which has a dynamic ID that is dynamically assigned/ new for every instance.
How do I enter text in the search box field?
CodePudding user response:
You can use the aria-label
for this like:
cy.get('input[aria-label="main-search-box-ui-lib-container"]').type('text')
CodePudding user response:
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