Search code examples
testingautomationautomated-testscypress

Cypress - how to get element by last word in it


If this is the ID -> div id="random_is_good"

I want to get this element but only to catch "_is_good"

how can i do it ?

Or I only have the start and end -> "random_ _good"


Solution

  • Symbol * - Match elements that with partial text match

    cy.get('[div*="_is_good"]')
    
    

    Symbol ^ - Match elements that starts with given value

    cy.get('div[id^="random_"]')
    

    Symbol $ - Match elements that ends with given value

    cy.get('div[id$="_good"]')