Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to find an element by using Or in the locator?

I have 2 very similar elements one different pages that I need to test:

<input name="myName">
<input name="name">

In my code I tried to find the input element using Or (||) keyword, but that did Not work.

Can this be done without xpath, only by using CSS expression?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

this._nameInput = page.locator(
    'input[name="name"]' || 'input[name*="Name"]'
)

>Solution :

You can use the or method:

lowercase = page.locator('input[name="name"]')
wildcard = page.locator('input[name*="Name"]');
this._nameInput = lowercase.or(wildcard);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading