Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cypress: Using multiple selector wih OR condition

I have multiple login pages as:

First login page

Input element is as:

<input placeholder="[email protected]" class="input" name="email" type="text" value="">

Cypress selector is as follows:

cy.get('input[name="email"]').as('email').click();

Second login page:

Input element is as:

<input id="email" type="email" required="required" class="input">

Cypress selector is as follows:

cy.get('input[id="email"]').as('email').click();

If we notice, the 1st input element has name=email while the 2nd has id=email.
Is there a way to write a cypress selector where it can look for selector input[name="email"] if not found it looks for input[id="email"]?

like image 597
Varun Sukheja Avatar asked Jun 03 '26 19:06

Varun Sukheja


1 Answers

You can use the comma , to do an OR condition if you are using css selectors. Something like:

cy.get('input[name="email"],input[id="email"]').click()
like image 66
Alapan Das Avatar answered Jun 06 '26 08:06

Alapan Das



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!