Skip to content
Advertisement

Cypress, look for multiple parameters like ID and Class

I was wondering if it’s possible to search by multiple parameters in cypress, for example ID and Class

it('find button',function(){ 
   cy.get('#button_id, .button-class').click()
})

is this something that is achievable???

Advertisement

Answer

Yes you can directly use #button_id.button-class

it('find button',function(){ 
   cy.get('#button_id.button-class').click()
})

In my local I cross created this element:

<div class="titleclass" id="titleid">Apple</div>

And in the test runner if you could see, I was able to use both class and id cy.get('#titleid.titleclass') and successfully get the element.

Test runner screenshot

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement